diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-09-08 11:23:09 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-09-08 11:23:09 -0300 |
| commit | 0de2065f4e7cbbbe301b07835b9dd0b1bd1a4bbb (patch) | |
| tree | 6f578771ff27c6a352b52ba721fbcf163c610945 /lgc.c | |
| parent | ee165043ef917688d6e9151fc1a98d1e0f3e6ab1 (diff) | |
| download | lua-0de2065f4e7cbbbe301b07835b9dd0b1bd1a4bbb.tar.gz lua-0de2065f4e7cbbbe301b07835b9dd0b1bd1a4bbb.tar.bz2 lua-0de2065f4e7cbbbe301b07835b9dd0b1bd1a4bbb.zip | |
tighter tests for stack overflow
Diffstat (limited to 'lgc.c')
| -rw-r--r-- | lgc.c | 17 |
1 files changed, 10 insertions, 7 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lgc.c,v 2.9 2004/08/24 20:12:06 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.10 2004/08/30 13:44:44 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 | */ |
| @@ -239,14 +239,17 @@ static void traverseclosure (global_State *g, Closure *cl) { | |||
| 239 | 239 | ||
| 240 | 240 | ||
| 241 | static void checkstacksizes (lua_State *L, StkId max) { | 241 | static void checkstacksizes (lua_State *L, StkId max) { |
| 242 | int used = L->ci - L->base_ci; /* number of `ci' in use */ | 242 | int ci_used = L->ci - L->base_ci; /* number of `ci' in use */ |
| 243 | if (4*used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci) | 243 | int s_used = max - L->stack; /* part of stack in use */ |
| 244 | if (L->size_ci > LUA_MAXCALLS) /* handling overflow? */ | ||
| 245 | return; /* do not touch the stacks */ | ||
| 246 | if (4*ci_used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci) | ||
| 244 | luaD_reallocCI(L, L->size_ci/2); /* still big enough... */ | 247 | luaD_reallocCI(L, L->size_ci/2); /* still big enough... */ |
| 245 | else condhardstacktests(luaD_reallocCI(L, L->size_ci)); | 248 | condhardstacktests(luaD_reallocCI(L, ci_used + 1)); |
| 246 | used = max - L->stack; /* part of stack in use */ | 249 | if (4*s_used < L->stacksize && |
| 247 | if (4*used < L->stacksize && 2*(BASIC_STACK_SIZE+EXTRA_STACK) < L->stacksize) | 250 | 2*(BASIC_STACK_SIZE+EXTRA_STACK) < L->stacksize) |
| 248 | luaD_reallocstack(L, L->stacksize/2); /* still big enough... */ | 251 | luaD_reallocstack(L, L->stacksize/2); /* still big enough... */ |
| 249 | else condhardstacktests(luaD_reallocstack(L, L->stacksize)); | 252 | condhardstacktests(luaD_reallocstack(L, s_used)); |
| 250 | } | 253 | } |
| 251 | 254 | ||
| 252 | 255 | ||
