A bug was discovered on IRC where an errant script was setting a nil
value on a property. This becomes a NaN when converted to a numeric value, which then percolated into the C++ world where it ultimately caused a crash in YASim's turbulence code. While converting nil to NaN isn't *strictly* wrong, it's dangerous for this reason. Toss a Nasal exception instead. Hopefully this won't break too much preexisting code.
This commit is contained in:
parent
4da02e3d99
commit
3362ea2447
2 changed files with 18 additions and 3 deletions
|
@ -213,7 +213,12 @@ static naRef f_setprop(naContext c, naRef me, int argc, naRef* args)
|
||||||
naRef val = args[argc-1];
|
naRef val = args[argc-1];
|
||||||
try {
|
try {
|
||||||
if(naIsString(val)) props->setStringValue(buf, naStr_data(val));
|
if(naIsString(val)) props->setStringValue(buf, naStr_data(val));
|
||||||
else props->setDoubleValue(buf, naNumValue(val).num);
|
else {
|
||||||
|
naRef n = naNumValue(val);
|
||||||
|
if(naIsNil(n))
|
||||||
|
naRuntimeError(c, "setprop() value is not string or number");
|
||||||
|
props->setDoubleValue(buf, n.num);
|
||||||
|
}
|
||||||
} catch (const string& err) {
|
} catch (const string& err) {
|
||||||
naRuntimeError(c, (char *)err.c_str());
|
naRuntimeError(c, (char *)err.c_str());
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,12 @@ static naRef f_setValue(naContext c, naRef me, int argc, naRef* args)
|
||||||
NODEARG();
|
NODEARG();
|
||||||
naRef val = naVec_get(argv, 0);
|
naRef val = naVec_get(argv, 0);
|
||||||
if(naIsString(val)) (*node)->setStringValue(naStr_data(val));
|
if(naIsString(val)) (*node)->setStringValue(naStr_data(val));
|
||||||
else (*node)->setDoubleValue(naNumValue(val).num);
|
else {
|
||||||
|
naRef n = naNumValue(val);
|
||||||
|
if(naIsNil(n))
|
||||||
|
naRuntimeError(c, "props.setValue() with non-number");
|
||||||
|
(*node)->setDoubleValue(naNumValue(val).num);
|
||||||
|
}
|
||||||
return naNil();
|
return naNil();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,6 +125,8 @@ static naRef f_setIntValue(naContext c, naRef me, int argc, naRef* args)
|
||||||
// Junk to pacify the gcc-2.95.3 optimizer:
|
// Junk to pacify the gcc-2.95.3 optimizer:
|
||||||
naRef tmp0 = naVec_get(argv, 0);
|
naRef tmp0 = naVec_get(argv, 0);
|
||||||
naRef tmp1 = naNumValue(tmp0);
|
naRef tmp1 = naNumValue(tmp0);
|
||||||
|
if(naIsNil(tmp1))
|
||||||
|
naRuntimeError(c, "props.setIntValue() with non-number");
|
||||||
double tmp2 = tmp1.num;
|
double tmp2 = tmp1.num;
|
||||||
int iv = (int)tmp2;
|
int iv = (int)tmp2;
|
||||||
|
|
||||||
|
@ -138,7 +145,10 @@ static naRef f_setBoolValue(naContext c, naRef me, int argc, naRef* args)
|
||||||
static naRef f_setDoubleValue(naContext c, naRef me, int argc, naRef* args)
|
static naRef f_setDoubleValue(naContext c, naRef me, int argc, naRef* args)
|
||||||
{
|
{
|
||||||
NODEARG();
|
NODEARG();
|
||||||
(*node)->setDoubleValue(naNumValue(naVec_get(argv, 0)).num);
|
naRef r = naNumValue(naVec_get(argv, 0));
|
||||||
|
if(naIsNil(r))
|
||||||
|
naRuntimeError(c, "props.setDoubleValue() with non-number");
|
||||||
|
(*node)->setDoubleValue(r.num);
|
||||||
return naNil();
|
return naNil();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue