1
0
Fork 0

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.
This commit is contained in:
ThorstenB 2010-12-05 21:26:51 +01:00
parent ebbd5bfd05
commit 138449f4bd
2 changed files with 11 additions and 6 deletions

View 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();
}

View 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 "";
}