diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-05-23 10:38:03 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-05-23 10:38:03 -0300 |
| commit | 4a00f61276a9a38b0427fbae3dbbd86dfb5a0749 (patch) | |
| tree | 16ed717a2f4b79bad0743c2a8888ba55e013a309 /lapi.c | |
| parent | 42d40581dd919fb134c07027ca1ce0844c670daf (diff) | |
| download | lua-4a00f61276a9a38b0427fbae3dbbd86dfb5a0749.tar.gz lua-4a00f61276a9a38b0427fbae3dbbd86dfb5a0749.tar.bz2 lua-4a00f61276a9a38b0427fbae3dbbd86dfb5a0749.zip | |
'lua_checkstack' doesn't need to check stack overflow
'luaD_growstack' already checks that. This commit also fixes an
internal bug in 'luaD_growstack': a large 'n' could cause an arithmetic
overflow when computing 'needed'.
Diffstat (limited to 'lapi.c')
| -rw-r--r-- | lapi.c | 9 |
1 files changed, 2 insertions, 7 deletions
| @@ -114,13 +114,8 @@ LUA_API int lua_checkstack (lua_State *L, int n) { | |||
| 114 | api_check(L, n >= 0, "negative 'n'"); | 114 | api_check(L, n >= 0, "negative 'n'"); |
| 115 | if (L->stack_last - L->top > n) /* stack large enough? */ | 115 | if (L->stack_last - L->top > n) /* stack large enough? */ |
| 116 | res = 1; /* yes; check is OK */ | 116 | res = 1; /* yes; check is OK */ |
| 117 | else { /* no; need to grow stack */ | 117 | else /* need to grow stack */ |
| 118 | int inuse = cast_int(L->top - L->stack) + EXTRA_STACK; | 118 | res = luaD_growstack(L, n, 0); |
| 119 | if (inuse > LUAI_MAXSTACK - n) /* can grow without overflow? */ | ||
| 120 | res = 0; /* no */ | ||
| 121 | else /* try to grow stack */ | ||
| 122 | res = luaD_growstack(L, n, 0); | ||
| 123 | } | ||
| 124 | if (res && ci->top < L->top + n) | 119 | if (res && ci->top < L->top + n) |
| 125 | ci->top = L->top + n; /* adjust frame top */ | 120 | ci->top = L->top + n; /* adjust frame top */ |
| 126 | lua_unlock(L); | 121 | lua_unlock(L); |
