diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-06-01 16:16:34 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-06-01 16:16:34 -0300 |
commit | 4bc33d64de9bb2c1cd96240337ba8486300759da (patch) | |
tree | 6f7c8b0a644ebb33fab416a6aecc8b3b8acbd150 /lgc.c | |
parent | 882174684147b2fbc3f3a740c463b199978d9286 (diff) | |
download | lua-4bc33d64de9bb2c1cd96240337ba8486300759da.tar.gz lua-4bc33d64de9bb2c1cd96240337ba8486300759da.tar.bz2 lua-4bc33d64de9bb2c1cd96240337ba8486300759da.zip |
avoid overflows in computation of step size
Diffstat (limited to 'lgc.c')
-rw-r--r-- | lgc.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 2.228 2017/05/04 13:32:01 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.229 2017/05/26 19:14:29 roberto Exp roberto $ |
3 | ** Garbage Collector | 3 | ** Garbage Collector |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -1486,7 +1486,9 @@ void luaC_runtilstate (lua_State *L, int statesmask) { | |||
1486 | static void incstep (lua_State *L, global_State *g) { | 1486 | static void incstep (lua_State *L, global_State *g) { |
1487 | int stepmul = (g->gcstepmul | 1); /* avoid division by 0 */ | 1487 | int stepmul = (g->gcstepmul | 1); /* avoid division by 0 */ |
1488 | l_mem debt = (g->GCdebt / WORK2MEM) * stepmul; | 1488 | l_mem debt = (g->GCdebt / WORK2MEM) * stepmul; |
1489 | l_mem stepsize = cast(l_mem, 1) << g->gcstepsize; | 1489 | l_mem stepsize = (g->gcstepsize <= log2maxs(l_mem)) |
1490 | ? cast(l_mem, 1) << g->gcstepsize | ||
1491 | : MAX_LMEM; | ||
1490 | stepsize = -((stepsize / WORK2MEM) * stepmul); | 1492 | stepsize = -((stepsize / WORK2MEM) * stepmul); |
1491 | do { /* repeat until pause or enough "credit" (negative debt) */ | 1493 | do { /* repeat until pause or enough "credit" (negative debt) */ |
1492 | lu_mem work = singlestep(L); /* perform one single step */ | 1494 | lu_mem work = singlestep(L); /* perform one single step */ |