mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-13 18:17:39 -04:00
Fix lua failure to catch divide by zero and NaN exceptions
I can only assume in the course of the original conversion to fixed point math in RbLua the fact that division by zero and NaN handling was to be caught as a graceful exception by the floating point handler was overlooked. As a result lua doesn't handle these exceptions and instead results in a panic on the device. This patch fixes this handling in the lexer for compile time Inf and Nan results and in the luavm for runtime division by zero (Inf) I missed the runtime exception of n%0 added checks for that as well.. Change-Id: I7746c087ea93678e5875f15ec6fe3f29f26bdb31
This commit is contained in:
parent
80bb6ccdc4
commit
9a9c7f2b7c
2 changed files with 33 additions and 8 deletions
|
@ -480,13 +480,35 @@ void luaV_execute (lua_State *L, int nexeccalls) {
|
|||
continue;
|
||||
}
|
||||
case OP_DIV: {
|
||||
arith_op(luai_numdiv, TM_DIV);
|
||||
TValue *rb = RKB(i);
|
||||
TValue *rc = RKC(i);
|
||||
if (ttisnumber(rb) && ttisnumber(rc)) {
|
||||
lua_Number nb = nvalue(rb), nc = nvalue(rc);
|
||||
if (nc == 0)
|
||||
luaG_typeerror(L, rc, "divide by zero");
|
||||
|
||||
setnvalue(ra, luai_numdiv(nb, nc));
|
||||
}
|
||||
else
|
||||
Protect(Arith(L, ra, rb, rc, TM_DIV));
|
||||
|
||||
continue;
|
||||
}
|
||||
case OP_MOD: {
|
||||
arith_op(luai_nummod, TM_MOD);
|
||||
TValue *rb = RKB(i);
|
||||
TValue *rc = RKC(i);
|
||||
if (ttisnumber(rb) && ttisnumber(rc)) {
|
||||
lua_Number nb = nvalue(rb), nc = nvalue(rc);
|
||||
if (nc == 0)
|
||||
luaG_typeerror(L, rc, "perform 'n%0'");
|
||||
|
||||
setnvalue(ra, luai_nummod(nb, nc));
|
||||
}
|
||||
else
|
||||
Protect(Arith(L, ra, rb, rc, TM_MOD));
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
case OP_POW: {
|
||||
arith_op(luai_numpow, TM_POW);
|
||||
continue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue