From: andy Date: Thu, 7 Jun 2007 16:17:48 +0000 (+0000) Subject: Allow the second (property node) argument to fgcommand() to be nil or X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b6930477034235a2bbe0c7a6b6b5a5e7c49c29c3;p=flightgear.git Allow the second (property node) argument to fgcommand() to be nil or missing, for sanity. Note that this will pass the resulting NULL pointer through into the underlying SGCommand handlers, some of which may be unprepared for it. So basically this is now yet another way you can use Nasal to exercise bugs and hose your sim; no biggie. --- diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index 133d8f740..7fb471b49 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -252,10 +252,13 @@ static naRef f_print(naContext c, naRef me, int argc, naRef* args) // an argument. static naRef f_fgcommand(naContext c, naRef me, int argc, naRef* args) { - if(argc < 2 || !naIsString(args[0]) || !naIsGhost(args[1])) + naRef cmd = argc > 0 ? args[0] : naNil(); + naRef props = argc > 1 ? args[1] : naNil(); + if(!naIsString(cmd) || (!naIsNil(props) && !naIsGhost(props))) naRuntimeError(c, "bad arguments to fgcommand()"); - naRef cmd = args[0], props = args[1]; - SGPropertyNode_ptr* node = (SGPropertyNode_ptr*)naGhost_ptr(props); + SGPropertyNode_ptr* node = NULL; + if(!naIsNil(props)) + node = (SGPropertyNode_ptr*)naGhost_ptr(props); return naNum(globals->get_commands()->execute(naStr_data(cmd), *node)); }