From d42a5d6d0df5160131becb0e9260624c0f0ee019 Mon Sep 17 00:00:00 2001 From: Fabian Lucke Date: Sat, 16 Sep 2023 22:32:23 +0200 Subject: [PATCH] FGEagels patch and strict line code checks for all lines covered by the patch Signed-off-by: Fabian Lucke --- src/Airports/GenAirports/helipad.cxx | 5 +++++ src/Airports/GenAirports/helipad.hxx | 6 ++++-- src/Airports/GenAirports/linked_objects.cxx | 15 +++++++++++++ src/Airports/GenAirports/linked_objects.hxx | 15 +++++++------ src/Airports/GenAirports/object.cxx | 5 +++++ src/Airports/GenAirports/object.hxx | 5 +++-- src/Airports/GenAirports/parser.cxx | 24 ++++++++++++++------- src/Airports/GenAirports/runway.cxx | 10 +++++++++ src/Airports/GenAirports/runway.hxx | 16 ++++++++------ src/Airports/GenAirports/taxiway.cxx | 7 +++++- src/Airports/GenAirports/taxiway.hxx | 6 ++++-- src/Lib/terragear/tg_surface.cxx | 1 + 12 files changed, 88 insertions(+), 27 deletions(-) diff --git a/src/Airports/GenAirports/helipad.cxx b/src/Airports/GenAirports/helipad.cxx index e59578fb..d203a109 100644 --- a/src/Airports/GenAirports/helipad.cxx +++ b/src/Airports/GenAirports/helipad.cxx @@ -34,6 +34,11 @@ Helipad::Helipad(char* definition) std::istringstream ss(definition); ss >> heli.designator >> heli.lat >> heli.lon >> heli.heading >> heli.length >> heli.width >> heli.surface >> heli.marking >> heli.shoulder >> heli.smoothness >> heli.edge_lights; + if (heli.length <= 0 || heli.width <= 0 || heli.lat < -90 || heli.lat > 90 || heli.lon < -180 || heli.lon > 180 || heli.surface < 1 || heli.surface > 57 || heli.shoulder < 0 || heli.shoulder > 2 || heli.smoothness < 0 || heli.smoothness > 1 || !(heli.edge_lights == 0 || heli.edge_lights == 1)) { + valid = false; + TG_LOG(SG_GENERAL, SG_ALERT, "Invalid helipad line: " << definition); + } + TG_LOG(SG_GENERAL, SG_DEBUG, "Read helipad: (" << heli.lon << "," << heli.lat << ") heading: " << heli.heading << " length: " << heli.length << " width: " << heli.width); } diff --git a/src/Airports/GenAirports/helipad.hxx b/src/Airports/GenAirports/helipad.hxx index 50bb3cc0..04ce7ace 100644 --- a/src/Airports/GenAirports/helipad.hxx +++ b/src/Airports/GenAirports/helipad.hxx @@ -54,12 +54,14 @@ public: tgcontour_list& slivers, tgAccumulator& accum); + bool valid {true}; + private: struct TGRunway { // data for helipad std::string designator; - double lat; - double lon; + double lat {-9999}; + double lon {-9999}; double heading; double length; double width; diff --git a/src/Airports/GenAirports/linked_objects.cxx b/src/Airports/GenAirports/linked_objects.cxx index c8360a79..83f5d596 100644 --- a/src/Airports/GenAirports/linked_objects.cxx +++ b/src/Airports/GenAirports/linked_objects.cxx @@ -9,6 +9,11 @@ Windsock::Windsock(char* definition) std::istringstream ss(definition); ss >> lat >> lon >> lit; + if (lat < -90 || lat > 90 || lon < -180 || lon > 180) { + valid = false; + TG_LOG(SG_GENERAL, SG_ALERT, "Invalid windsock line: " << definition); + } + TG_LOG(SG_GENERAL, SG_DEBUG, "Read Windsock: (" << lon << "," << lat << ") lit: " << lit); } @@ -17,6 +22,11 @@ Beacon::Beacon(char* definition) std::istringstream ss(definition); ss >> lat >> lon >> code; + if (lat < -90 || lat > 90 || lon < -180 || lon > 180) { + valid = false; + TG_LOG(SG_GENERAL, SG_ALERT, "Invalid beacon line: " << definition); + } + TG_LOG(SG_GENERAL, SG_DEBUG, "Read Beacon: (" << lon << "," << lat << ") code: " << code); } @@ -28,6 +38,11 @@ Sign::Sign(char* definition) std::istringstream ss(definition); ss >> lat >> lon >> def_heading >> reserved >> size >> sgdef; + if (lat < -90 || lat > 90 || lon < -180 || lon > 180 || size < 1 || size > 5) { + valid = false; + TG_LOG(SG_GENERAL, SG_ALERT, "Invalid sign line: " << definition); + } + // 850 format sign heading is the heading which points away from the visible numbers // Flightgear wants the heading to be the heading in which the sign is read heading = -def_heading + 360.0; diff --git a/src/Airports/GenAirports/linked_objects.hxx b/src/Airports/GenAirports/linked_objects.hxx index 63d60bdc..ba21d30f 100644 --- a/src/Airports/GenAirports/linked_objects.hxx +++ b/src/Airports/GenAirports/linked_objects.hxx @@ -10,9 +10,10 @@ class Windsock public: explicit Windsock(char* def); - double lat; - double lon; + double lat {-9999}; + double lon {-9999}; int lit; + bool valid {true}; SGGeod GetLoc() const { @@ -33,9 +34,10 @@ class Beacon public: explicit Beacon(char* def); - double lat; - double lon; + double lat {-9999}; + double lon {-9999}; int code; + bool valid {true}; SGGeod GetLoc() const { @@ -55,12 +57,13 @@ class Sign public: explicit Sign(char* def); - double lat; - double lon; + double lat {-9999}; + double lon {-9999}; double heading; int reserved; int size; std::string sgn_def; + bool valid {true}; SGGeod GetLoc() const { diff --git a/src/Airports/GenAirports/object.cxx b/src/Airports/GenAirports/object.cxx index c249f4f7..9e22ce42 100644 --- a/src/Airports/GenAirports/object.cxx +++ b/src/Airports/GenAirports/object.cxx @@ -10,6 +10,11 @@ LightingObj::LightingObj(char* definition) std::istringstream ss(definition); ss >> lat >> lon >> type >> heading >> glideslope >> assoc_rw; + if (lat < -90 || lat > 90 || lon < -180 || lon > 180 || type < 1 || type > 6 || heading < 0 || heading > 360) { + valid = false; + TG_LOG(SG_GENERAL, SG_ALERT, "Invalid lighting object line: " << definition); + } + TG_LOG(SG_GENERAL, SG_DEBUG, "Read lighting object: (" << lon << "," << lat << ") heading: " << heading << " type: " << type); } diff --git a/src/Airports/GenAirports/object.hxx b/src/Airports/GenAirports/object.hxx index 2176c44a..88238e4a 100644 --- a/src/Airports/GenAirports/object.hxx +++ b/src/Airports/GenAirports/object.hxx @@ -11,12 +11,13 @@ class LightingObj public: explicit LightingObj(char* def); - double lat; - double lon; + double lat {-9999}; + double lon {-9999}; int type; double heading; double glideslope; char assoc_rw; + bool valid {true}; void BuildBtg(tglightcontour_list& lights); diff --git a/src/Airports/GenAirports/parser.cxx b/src/Airports/GenAirports/parser.cxx index e121f87d..83c50f93 100644 --- a/src/Airports/GenAirports/parser.cxx +++ b/src/Airports/GenAirports/parser.cxx @@ -492,7 +492,7 @@ int Parser::ParseLine(char* line) SetState(STATE_PARSE_SIMPLE); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing runway: " << line); cur_runway = std::make_shared(line); - if (cur_airport) { + if (cur_airport && cur_runway->valid) { cur_airport->AddRunway(cur_runway); } break; @@ -501,7 +501,7 @@ int Parser::ParseLine(char* line) SetState(STATE_PARSE_SIMPLE); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing water runway: " << line); cur_waterRunway = std::make_shared(line); - if (cur_airport) { + if (cur_airport && cur_waterRunway->valid) { cur_airport->AddWaterRunway(cur_waterRunway); } break; @@ -509,7 +509,7 @@ int Parser::ParseLine(char* line) SetState(STATE_PARSE_SIMPLE); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing helipad: " << line); cur_helipad = std::make_shared(line); - if (cur_airport) { + if (cur_airport && cur_helipad->valid) { cur_airport->AddHelipad(cur_helipad); } break; @@ -518,7 +518,7 @@ int Parser::ParseLine(char* line) SetState(STATE_PARSE_SIMPLE); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing taxiway: " << line); cur_taxiway = std::make_shared(line); - if (cur_airport) { + if (cur_airport && cur_taxiway->valid) { cur_airport->AddTaxiway(cur_taxiway); } break; @@ -643,25 +643,33 @@ int Parser::ParseLine(char* line) SetState(STATE_PARSE_SIMPLE); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing light beacon: " << line); cur_beacon = std::make_shared(line); - cur_airport->AddBeacon(cur_beacon); + if (cur_airport && cur_beacon->valid) { + cur_airport->AddBeacon(cur_beacon); + } break; case WINDSOCK_CODE: SetState(STATE_PARSE_SIMPLE); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing windsock: " << line); cur_windsock = std::make_shared(line); - cur_airport->AddWindsock(cur_windsock); + if (cur_airport && cur_windsock->valid) { + cur_airport->AddWindsock(cur_windsock); + } break; case TAXIWAY_SIGN: SetState(STATE_PARSE_SIMPLE); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing taxiway sign: " << line); cur_sign = std::make_shared(line); - cur_airport->AddSign(cur_sign); + if (cur_airport && cur_sign->valid) { + cur_airport->AddSign(cur_sign); + } break; case LIGHTING_OBJECT: SetState(STATE_PARSE_SIMPLE); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing lighting object: " << line); cur_object = std::make_shared(line); - cur_airport->AddObj(cur_object); + if (cur_airport && cur_object->valid) { + cur_airport->AddObj(cur_object); + } break; case COMM_FREQ1_CODE: diff --git a/src/Airports/GenAirports/runway.cxx b/src/Airports/GenAirports/runway.cxx index 1b028659..63c80cb3 100644 --- a/src/Airports/GenAirports/runway.cxx +++ b/src/Airports/GenAirports/runway.cxx @@ -65,6 +65,11 @@ Runway::Runway(char* definition) >> rwy.tz_lights[1] >> rwy.reil[1]; + if (rwy.width == -9999 || rwy.lat[0] < -90 || rwy.lat[0] > 90 || rwy.lon[0] < -180 || rwy.lon[0] > 180 || rwy.lat[1] < -90 || rwy.lat[1] > 90 || rwy.lon[1] < -180 || rwy.lon[1] > 180 || rwy.smoothness > 1 || rwy.smoothness < 0 || !(rwy.centerline_lights == 0 || rwy.centerline_lights == 1) || rwy.edge_lights < 0 || rwy.edge_lights > 3 || !(rwy.dist_remain_signs == 0 || rwy.dist_remain_signs == 1) || rwy.marking[0] < 0 || rwy.marking[0] > 7 || rwy.marking[1] < 0 || rwy.marking[1] > 7 || rwy.approach_lights[0] < 0 || rwy.approach_lights[0] > 12 || rwy.approach_lights[1] < 0 || rwy.approach_lights[1] > 12 || !(rwy.tz_lights[0] == 0 || rwy.tz_lights[0] == 1) || !(rwy.tz_lights[1] == 0 || rwy.tz_lights[1] == 1) || rwy.reil[0] < 0 || rwy.reil[0] > 2 || rwy.reil[1] < 0 || rwy.reil[1] > 2 || rwy.surface < 1 || rwy.surface > 57) { + valid = false; + TG_LOG(SG_GENERAL, SG_ALERT, "Invalid runway line: " << definition); + } + // calculate runway heading and length (used a lot) SGGeodesy::inverse(GetStart(), GetEnd(), rwy.heading, az2, rwy.length); @@ -88,6 +93,11 @@ WaterRunway::WaterRunway(char* definition) >> lat[1] >> lon[1]; + if (width == -9999 || lat[0] < -90 || lat[0] > 90 || lon[0] < -180 || lon[0] > 180 || lat[1] < -90 || lat[1] > 90 || lon[1] < -180 || lon[1] > 180 || !(buoys == 0 || buoys == 1)) { + valid = false; + TG_LOG(SG_GENERAL, SG_ALERT, "Invalid water runway line: " << definition); + } + TG_LOG(SG_GENERAL, SG_DEBUG, "Read water runway: (" << lon[0] << "," << lat[0] << ") to (" << lon[1] << "," << lat[1] << ") width: " << width << diff --git a/src/Airports/GenAirports/runway.hxx b/src/Airports/GenAirports/runway.hxx index 89691177..26aafda4 100644 --- a/src/Airports/GenAirports/runway.hxx +++ b/src/Airports/GenAirports/runway.hxx @@ -52,6 +52,8 @@ public: tgcontour_list& slivers, tgAccumulator& accum); + bool valid {true}; + private: struct TGRunway { // data for the whole runway @@ -61,15 +63,15 @@ private: int edge_lights; int dist_remain_signs; - double width; + double width {-9999}; double length; double heading; double smoothness; // data for each end char rwnum[2][16]; - double lat[2]; - double lon[2]; + double lat[2] {-9999, -9999}; + double lon[2] {-9999, -9999}; double threshold[2]; double overrun[2]; @@ -197,12 +199,14 @@ public: return SGGeod::fromDeg(lon[1], lat[1]); } + bool valid {true}; + private: - double width; + double width {-9999}; int buoys; char rwnum[2][16]; - double lat[2]; - double lon[2]; + double lat[2] {-9999, -9999}; + double lon[2] {-9999, -9999}; }; typedef std::vector> WaterRunwayList; diff --git a/src/Airports/GenAirports/taxiway.cxx b/src/Airports/GenAirports/taxiway.cxx index 6d08bd6c..54dd7d21 100644 --- a/src/Airports/GenAirports/taxiway.cxx +++ b/src/Airports/GenAirports/taxiway.cxx @@ -16,7 +16,7 @@ extern int nudge; Taxiway::Taxiway(char* definition) { // variables for adjusting 810 rwy format to 850 rwy format - double lon = 0, lat = 0; + double lon = -9999, lat = -9999; // variables to store unused parameters char designation[16]; @@ -50,6 +50,11 @@ Taxiway::Taxiway(char* definition) smoothness >> signs; + if (width == -9999 || length == -9999 || lat < -90 || lat > 90 || lon < -180 || lon > 180) { + valid = false; + TG_LOG(SG_GENERAL, SG_ALERT, "Invalid taxiway line: " << definition); + } + TG_LOG(SG_GENERAL, SG_DEBUG, "Read taxiway: (" << lon << "," << lat << ") heading: " << heading << " length: " << length << " width: " << width); // adjust length and width from feet to meters diff --git a/src/Airports/GenAirports/taxiway.hxx b/src/Airports/GenAirports/taxiway.hxx index 25c2efdf..5085c810 100644 --- a/src/Airports/GenAirports/taxiway.hxx +++ b/src/Airports/GenAirports/taxiway.hxx @@ -28,11 +28,13 @@ public: tgAccumulator& accum, std::string& shapefile_name); + bool valid {true}; + private: SGGeod origin; double heading; - double length; - double width; + double length {-9999}; + double width {-9999}; int surface; char lighting[6]; diff --git a/src/Lib/terragear/tg_surface.cxx b/src/Lib/terragear/tg_surface.cxx index 125f393b..db5a522f 100644 --- a/src/Lib/terragear/tg_surface.cxx +++ b/src/Lib/terragear/tg_surface.cxx @@ -269,6 +269,7 @@ tgSurface::tgSurface( const std::string& path, // Build the extra res input grid (shifted SW by half (dlon,dlat) // with an added major row column on the NE sides.) int mult = 10; + SG_LOG(SG_GENERAL, SG_ALERT, "creating tgMatrix with nPts x=" << ((xdivs + 1) * mult + 1) << " y=" << ((ydivs + 1) * mult + 1)); tgMatrix dPts( (xdivs + 1) * mult + 1, (ydivs + 1) * mult + 1 ); for ( int j = 0; j < dPts.rows(); ++j ) { for ( int i = 0; i < dPts.cols(); ++i ) {