From 77d7476ba66ec6e186f76cd7e010f96f6044fd92 Mon Sep 17 00:00:00 2001 From: Automatic Release Builder Date: Thu, 29 Oct 2020 11:48:16 +0000 Subject: [PATCH] Fix route-path crashes on empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This could be triggered by doing ‘view route’ in the launcher flight- planning code, wit no route defined. --- src/Navaids/routePath.cxx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Navaids/routePath.cxx b/src/Navaids/routePath.cxx index 3fc2c0e13..db6370911 100644 --- a/src/Navaids/routePath.cxx +++ b/src/Navaids/routePath.cxx @@ -935,6 +935,10 @@ void RoutePath::commonInit() SGGeodVec RoutePath::pathForIndex(int index) const { + if ((index < 0) || (index >= static_cast(d->waypoints.size()))) { + return {}; + } + const WayptData& w(d->waypoints[index]); const std::string& ty(w.wpt->type()); SGGeodVec r; @@ -1029,6 +1033,10 @@ void RoutePath::interpolateGreatCircle(const SGGeod& aFrom, const SGGeod& aTo, S SGGeod RoutePath::positionForIndex(int index) const { + if ((index < 0) || (index >= static_cast(d->waypoints.size()))) { + return {}; + } + return d->waypoints[index].pos; } @@ -1096,9 +1104,8 @@ SGGeodVec RoutePath::pathForHold(Hold* hold) const double RoutePath::computeDistanceForIndex(int index) const { - if ((index < 0) || (index >= (int) d->waypoints.size())) { - throw sg_range_exception("waypt index out of range", - "RoutePath::computeDistanceForIndex"); + if ((index < 0) || (index >= static_cast(d->waypoints.size()))) { + return 0.0; } auto it = d->waypoints.begin() + index;