Bug: Wrong line in error message for arith. errors

It also causes 'L->top' to be wrong when the error happens,
triggering an 'assert'.
This commit is contained in:
Roberto Ierusalimschy 2023-02-08 14:15:41 -03:00
parent 5e08b41567
commit 02bab9fc25
2 changed files with 12 additions and 0 deletions

4
lvm.c
View File

@ -1410,6 +1410,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
vmbreak; vmbreak;
} }
vmcase(OP_MODK) { vmcase(OP_MODK) {
savestate(L, ci); /* in case of division by 0 */
op_arithK(L, luaV_mod, luaV_modf); op_arithK(L, luaV_mod, luaV_modf);
vmbreak; vmbreak;
} }
@ -1422,6 +1423,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
vmbreak; vmbreak;
} }
vmcase(OP_IDIVK) { vmcase(OP_IDIVK) {
savestate(L, ci); /* in case of division by 0 */
op_arithK(L, luaV_idiv, luai_numidiv); op_arithK(L, luaV_idiv, luai_numidiv);
vmbreak; vmbreak;
} }
@ -1470,6 +1472,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
vmbreak; vmbreak;
} }
vmcase(OP_MOD) { vmcase(OP_MOD) {
savestate(L, ci); /* in case of division by 0 */
op_arith(L, luaV_mod, luaV_modf); op_arith(L, luaV_mod, luaV_modf);
vmbreak; vmbreak;
} }
@ -1482,6 +1485,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
vmbreak; vmbreak;
} }
vmcase(OP_IDIV) { /* floor division */ vmcase(OP_IDIV) { /* floor division */
savestate(L, ci); /* in case of division by 0 */
op_arith(L, luaV_idiv, luai_numidiv); op_arith(L, luaV_idiv, luai_numidiv);
vmbreak; vmbreak;
} }

View File

@ -444,6 +444,14 @@ if not b then
end end
end]], 5) end]], 5)
-- bug in 5.4.0
lineerror([[
local a = 0
local b = 1
local c = b % a
]], 3)
do do
-- Force a negative estimate for base line. Error in instruction 2 -- Force a negative estimate for base line. Error in instruction 2
-- (after VARARGPREP, GETGLOBAL), with first absolute line information -- (after VARARGPREP, GETGLOBAL), with first absolute line information