From f5b352429c7dc8f2d88a665fd575ef2d7a8a76b6 Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 1 Oct 2013 19:57:07 +0100 Subject: [PATCH] Bug 1176, crash loading malformed scenario. http://code.google.com/p/flightgear-bugs/issues/detail?id=1176 Don't crash if a scenario specifies a missing or invalid flightplan (check the flightplan is valid before setting it) --- src/AIModel/AIAircraft.cxx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/AIModel/AIAircraft.cxx b/src/AIModel/AIAircraft.cxx index 101be110b..eac696d10 100644 --- a/src/AIModel/AIAircraft.cxx +++ b/src/AIModel/AIAircraft.cxx @@ -235,11 +235,19 @@ double FGAIAircraft::sign(double x) { } -void FGAIAircraft::setFlightPlan(const std::string& flightplan, bool repeat) { - if (!flightplan.empty()) { - FGAIFlightPlan* fp = new FGAIFlightPlan(flightplan); +void FGAIAircraft::setFlightPlan(const std::string& flightplan, bool repeat) +{ + if (flightplan.empty()) { + SG_LOG(SG_AI, SG_WARN, "setFlightPlan: empty flight plan"); + } + + FGAIFlightPlan* fp = new FGAIFlightPlan(flightplan); + if (fp->isValidPlan()) { fp->setRepeat(repeat); SetFlightPlan(fp); + } else { + SG_LOG(SG_AI, SG_WARN, "setFlightPlan: invalid flightplan specified:" << flightplan); + delete fp; } }