diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-07-04 13:31:03 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-07-04 13:31:03 -0300 |
commit | 319ccfefbc651fa22f264bdfa872ffe59cc81151 (patch) | |
tree | d12dcd34ed695898a5a1052fff36ec97706bd8b2 | |
parent | 6a8400ba4f5bee9be5831e06d0686e2d617fbf27 (diff) | |
download | lua-319ccfefbc651fa22f264bdfa872ffe59cc81151.tar.gz lua-319ccfefbc651fa22f264bdfa872ffe59cc81151.tar.bz2 lua-319ccfefbc651fa22f264bdfa872ffe59cc81151.zip |
computations in numerical for loop must avoid overflows too
-rw-r--r-- | lvm.c | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.245 2015/06/09 15:53:35 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.246 2015/06/25 14:00:01 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -1139,7 +1139,7 @@ void luaV_execute (lua_State *L) { | |||
1139 | vmcase(OP_FORLOOP) { | 1139 | vmcase(OP_FORLOOP) { |
1140 | if (ttisinteger(ra)) { /* integer loop? */ | 1140 | if (ttisinteger(ra)) { /* integer loop? */ |
1141 | lua_Integer step = ivalue(ra + 2); | 1141 | lua_Integer step = ivalue(ra + 2); |
1142 | lua_Integer idx = ivalue(ra) + step; /* increment index */ | 1142 | lua_Integer idx = intop(+, ivalue(ra), step); /* increment index */ |
1143 | lua_Integer limit = ivalue(ra + 1); | 1143 | lua_Integer limit = ivalue(ra + 1); |
1144 | if ((0 < step) ? (idx <= limit) : (limit <= idx)) { | 1144 | if ((0 < step) ? (idx <= limit) : (limit <= idx)) { |
1145 | ci->u.l.savedpc += GETARG_sBx(i); /* jump back */ | 1145 | ci->u.l.savedpc += GETARG_sBx(i); /* jump back */ |
@@ -1171,7 +1171,7 @@ void luaV_execute (lua_State *L) { | |||
1171 | /* all values are integer */ | 1171 | /* all values are integer */ |
1172 | lua_Integer initv = (stopnow ? 0 : ivalue(init)); | 1172 | lua_Integer initv = (stopnow ? 0 : ivalue(init)); |
1173 | setivalue(plimit, ilimit); | 1173 | setivalue(plimit, ilimit); |
1174 | setivalue(init, initv - ivalue(pstep)); | 1174 | setivalue(init, intop(-, initv, ivalue(pstep))); |
1175 | } | 1175 | } |
1176 | else { /* try making all values floats */ | 1176 | else { /* try making all values floats */ |
1177 | lua_Number ninit; lua_Number nlimit; lua_Number nstep; | 1177 | lua_Number ninit; lua_Number nlimit; lua_Number nstep; |