From 319ccfefbc651fa22f264bdfa872ffe59cc81151 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Sat, 4 Jul 2015 13:31:03 -0300 Subject: [PATCH] computations in numerical for loop must avoid overflows too --- lvm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lvm.c b/lvm.c index e51e7f13..164fe476 100644 --- a/lvm.c +++ b/lvm.c @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 2.245 2015/06/09 15:53:35 roberto Exp roberto $ +** $Id: lvm.c,v 2.246 2015/06/25 14:00:01 roberto Exp roberto $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -1139,7 +1139,7 @@ void luaV_execute (lua_State *L) { vmcase(OP_FORLOOP) { if (ttisinteger(ra)) { /* integer loop? */ lua_Integer step = ivalue(ra + 2); - lua_Integer idx = ivalue(ra) + step; /* increment index */ + lua_Integer idx = intop(+, ivalue(ra), step); /* increment index */ lua_Integer limit = ivalue(ra + 1); if ((0 < step) ? (idx <= limit) : (limit <= idx)) { ci->u.l.savedpc += GETARG_sBx(i); /* jump back */ @@ -1171,7 +1171,7 @@ void luaV_execute (lua_State *L) { /* all values are integer */ lua_Integer initv = (stopnow ? 0 : ivalue(init)); setivalue(plimit, ilimit); - setivalue(init, initv - ivalue(pstep)); + setivalue(init, intop(-, initv, ivalue(pstep))); } else { /* try making all values floats */ lua_Number ninit; lua_Number nlimit; lua_Number nstep;