1
0
Fork 0

Correct whitespace in NasalPositioned.cxx; fix segfault in NasalPositioned by adding null check in the legGhostGetMember method; add test case for segfault

This commit is contained in:
legoboyvdlp R 2020-01-27 16:27:46 +00:00
parent f6285bc528
commit b920a09fcf
3 changed files with 109 additions and 77 deletions
src/Scripting
test_suite/unit_tests/Navaids

View file

@ -701,6 +701,12 @@ static const char* legGhostGetMember(naContext c, void* g, naRef field, naRef* o
{
const char* fieldName = naStr_data(field);
FlightPlan::Leg* leg = (FlightPlan::Leg*) g;
if (!leg) {
*out = naNil();
naRuntimeError(c, "leg ghost member fetched, but no associated leg object found");
return "";
}
Waypt* wpt = leg->waypoint();
if (!strcmp(fieldName, "parents")) {
@ -732,7 +738,11 @@ static const char* legGhostGetMember(naContext c, void* g, naRef field, naRef* o
} else if (!strcmp(fieldName, "hold_count")) {
*out = naNum(leg->holdCount());
} else { // check for fields defined on the underlying waypoint
if (wpt) { // FIXME null check shouldn't be required, check refcount
return waypointCommonGetMember(c, wpt, fieldName, out);
} else {
naRuntimeError(c, "leg ghost member fetched, but no underlying waypoint object found");
}
}
return ""; // success

View file

@ -24,6 +24,13 @@ void FlightplanTests::setUp()
{
FGTestApi::setUp::initTestGlobals("flightplan");
FGTestApi::setUp::initNavDataCache();
globals->get_subsystem_mgr()->init();
FGTestApi::setUp::initStandardNasal();
globals->get_subsystem_mgr()->postinit();
globals->get_subsystem_mgr()->bind();
}
@ -320,3 +327,16 @@ void FlightplanTests::testBug1814()
CPPUNIT_ASSERT_DOUBLES_EQUAL(137, leg->distanceNm(), 0.5);
CPPUNIT_ASSERT_DOUBLES_EQUAL(101, f->legAtIndex(2)->distanceNm(), 0.5);
}
void FlightplanTests::testSegfaultWaypointGhost() {
// checking for a segfault here, no segfault indicates success. A runtime error in the log is acceptable here.
bool ok = FGTestApi::executeNasal(R"(
var fp = createFlightplan();
fp.departure = airportinfo("BIKF");
fp.destination = airportinfo("EGLL");
var wp = fp.getWP(1);
fp.deleteWP(1);
print(wp.wp_name);
)");
CPPUNIT_ASSERT(ok);
}

View file

@ -38,6 +38,7 @@ class FlightplanTests : public CppUnit::TestFixture
CPPUNIT_TEST(testBasicAirways);
CPPUNIT_TEST(testAirwayNetworkRoute);
CPPUNIT_TEST(testBug1814);
CPPUNIT_TEST(testSegfaultWaypointGhost);
CPPUNIT_TEST(testRoutPathWpt0Midflight);
CPPUNIT_TEST(testRoutePathVec);
@ -62,6 +63,7 @@ public:
void testParseICAORoute();
void testParseICANLowLevelRoute();
void testBug1814();
void testSegfaultWaypointGhost();
void testRoutPathWpt0Midflight();
void testRoutePathVec();
};