1
0
Fork 0

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:
andy 2006-10-17 19:58:33 +00:00
parent 4da02e3d99
commit 3362ea2447
2 changed files with 18 additions and 3 deletions

View file

@ -213,7 +213,12 @@ static naRef f_setprop(naContext c, naRef me, int argc, naRef* args)
naRef val = args[argc-1];
try {
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) {
naRuntimeError(c, (char *)err.c_str());
}

View file

@ -107,7 +107,12 @@ static naRef f_setValue(naContext c, naRef me, int argc, naRef* args)
NODEARG();
naRef val = naVec_get(argv, 0);
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();
}
@ -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:
naRef tmp0 = naVec_get(argv, 0);
naRef tmp1 = naNumValue(tmp0);
if(naIsNil(tmp1))
naRuntimeError(c, "props.setIntValue() with non-number");
double tmp2 = tmp1.num;
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)
{
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();
}