From: ThorstenB Date: Sun, 5 Dec 2010 20:26:51 +0000 (+0100) Subject: Avoid exceptions in route manager module. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=138449f4bd677884d1968461fa7a0c0d47194c4a;p=flightgear.git Avoid exceptions in route manager module. Avoid segfaults in gps when route manager doesn't throw exceptions. Minor fix when removing waypoints by negative index. --- diff --git a/src/Autopilot/route_mgr.cxx b/src/Autopilot/route_mgr.cxx index c0f8f2631..1530497e8 100644 --- a/src/Autopilot/route_mgr.cxx +++ b/src/Autopilot/route_mgr.cxx @@ -345,7 +345,7 @@ flightgear::WayptRef FGRouteMgr::removeWayptAtIndex(int aIndex) { int index = aIndex; if (aIndex < 0) { // negative indices count the the end - index = _route.size() - index; + index = _route.size() + index; } if ((index < 0) || (index >= numWaypts())) { @@ -1027,7 +1027,7 @@ void FGRouteMgr::jumpToIndex(int index) void FGRouteMgr::currentWaypointChanged() { - Waypt* cur = (_currentIndexgetChild("id")->setStringValue(cur ? cur->ident() : ""); @@ -1050,6 +1050,8 @@ int FGRouteMgr::findWayptIndex(const SGGeod& aPos) const Waypt* FGRouteMgr::currentWaypt() const { + if ((_currentIndex < 0) || (_currentIndex >= numWaypts())) + return NULL; return wayptAtIndex(_currentIndex); } @@ -1064,7 +1066,7 @@ Waypt* FGRouteMgr::previousWaypt() const Waypt* FGRouteMgr::nextWaypt() const { - if ((_currentIndex + 1) >= numWaypts()) { + if ((_currentIndex < 0) || ((_currentIndex + 1) >= numWaypts())) { return NULL; } @@ -1353,4 +1355,3 @@ void FGRouteMgr::setDestinationICAO(const char* aIdent) arrivalChanged(); } - diff --git a/src/Instrumentation/gps.cxx b/src/Instrumentation/gps.cxx index 1add1b97f..7e4b2b398 100644 --- a/src/Instrumentation/gps.cxx +++ b/src/Instrumentation/gps.cxx @@ -697,6 +697,8 @@ void GPS::routeManagerSequenced() int index = _routeMgr->currentIndex(), count = _routeMgr->numWaypts(); if ((index < 0) || (index >= count)) { + _currentWaypt=NULL; + _prevWaypt=NULL; SG_LOG(SG_INSTR, SG_ALERT, "GPS: malformed route, index=" << index); return; } @@ -971,6 +973,8 @@ void GPS::driveAutopilot() void GPS::wp1Changed() { + if (!_currentWaypt) + return; if (_mode == "leg") { _wayptController.reset(WayptController::createForWaypt(this, _currentWaypt)); } else if (_mode == "obs") { @@ -1082,7 +1086,7 @@ double GPS::getCDIDeflection() const const char* GPS::getWP0Ident() const { - if (!_dataValid || (_mode != "leg")) { + if (!_dataValid || (_mode != "leg") || (!_prevWaypt)) { return ""; } @@ -1096,7 +1100,7 @@ const char* GPS::getWP0Name() const const char* GPS::getWP1Ident() const { - if (!_dataValid) { + if ((!_dataValid)||(!_currentWaypt)) { return ""; }