commit 319ccfefbc651fa22f264bdfa872ffe59cc81151
parent 6a8400ba4f5bee9be5831e06d0686e2d617fbf27
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Sat, 4 Jul 2015 13:30:37 -0300
computations in numerical for loop must avoid overflows too
Diffstat:
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git 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;