From ede92fce54698f55ef02067a6170e0b60dbc0eed Mon Sep 17 00:00:00 2001 From: Christian Schmitt Date: Wed, 28 Sep 2011 10:03:23 +0200 Subject: [PATCH] Fix a segfault that became apparent with a 850 apt.dat file --- src/Airports/apt_loader.cxx | 39 +++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/Airports/apt_loader.cxx b/src/Airports/apt_loader.cxx index 5698eb16b..eca0afb5c 100644 --- a/src/Airports/apt_loader.cxx +++ b/src/Airports/apt_loader.cxx @@ -478,25 +478,30 @@ private: int freqKhz = atoi(token[1].c_str()); int rangeNm = 50; FGPositioned::Type ty; - switch (lineId) { - case 50: - ty = FGPositioned::FREQ_AWOS; - if (token[2] == "ATIS") { - ty = FGPositioned::FREQ_ATIS; + // Make sure we only pass on stations with at least a name + if (token.size() >2){ + + switch (lineId) { + case 50: + ty = FGPositioned::FREQ_AWOS; + if (token[2] == "ATIS") { + ty = FGPositioned::FREQ_ATIS; + } + break; + + case 51: ty = FGPositioned::FREQ_UNICOM; break; + case 52: ty = FGPositioned::FREQ_CLEARANCE; break; + case 53: ty = FGPositioned::FREQ_GROUND; break; + case 54: ty = FGPositioned::FREQ_TOWER; break; + case 55: + case 56: ty = FGPositioned::FREQ_APP_DEP; break; + default: + throw sg_range_exception("unupported apt.dat comm station type"); } - break; - - case 51: ty = FGPositioned::FREQ_UNICOM; break; - case 52: ty = FGPositioned::FREQ_CLEARANCE; break; - case 53: ty = FGPositioned::FREQ_GROUND; break; - case 54: ty = FGPositioned::FREQ_TOWER; break; - case 55: - case 56: ty = FGPositioned::FREQ_APP_DEP; break; - default: - throw sg_range_exception("unupported apt.dat comm station type"); - } - commStations.push_back(new flightgear::CommStation(token[2], ty, pos, rangeNm, freqKhz)); + commStations.push_back(new flightgear::CommStation(token[2], ty, pos, rangeNm, freqKhz)); + } + else SG_LOG( SG_GENERAL, SG_DEBUG, "Found unnamed comm. Skipping: " << lineId); } }; -- 2.39.5