]> git.mxchange.org Git - flightgear.git/commitdiff
Avoid exceptions in route manager module.
authorThorstenB <brehmt@gmail.com>
Sun, 5 Dec 2010 20:26:51 +0000 (21:26 +0100)
committerThorstenB <brehmt@gmail.com>
Sun, 5 Dec 2010 20:26:51 +0000 (21:26 +0100)
Avoid segfaults in gps when route manager doesn't throw exceptions.
Minor fix when removing waypoints by negative index.

src/Autopilot/route_mgr.cxx
src/Instrumentation/gps.cxx

index c0f8f26318f33315e505199b9892e8b0855f2344..1530497e8395c4f41e695f611a34c3012159c3b0 100644 (file)
@@ -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 = (_currentIndex<numWaypts()) ? currentWaypt() : NULL;
+  Waypt* cur = currentWaypt();
   Waypt* next = nextWaypt();
 
   wp0->getChild("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();
 }
-    
index 1add1b97f1187a7b57dc0065d7efcd0e5454db0b..7e4b2b398f80bd7eef03c5e705d6b0505195b04d 100644 (file)
@@ -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 "";
   }