From 4a00f61276a9a38b0427fbae3dbbd86dfb5a0749 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 23 May 2022 10:38:03 -0300 Subject: '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'. --- lapi.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'lapi.c') diff --git a/lapi.c b/lapi.c index 5ee65792..352a385a 100644 --- a/lapi.c +++ b/lapi.c @@ -114,13 +114,8 @@ LUA_API int lua_checkstack (lua_State *L, int n) { api_check(L, n >= 0, "negative 'n'"); if (L->stack_last - L->top > n) /* stack large enough? */ res = 1; /* yes; check is OK */ - else { /* no; need to grow stack */ - int inuse = cast_int(L->top - L->stack) + EXTRA_STACK; - if (inuse > LUAI_MAXSTACK - n) /* can grow without overflow? */ - res = 0; /* no */ - else /* try to grow stack */ - res = luaD_growstack(L, n, 0); - } + else /* need to grow stack */ + res = luaD_growstack(L, n, 0); if (res && ci->top < L->top + n) ci->top = L->top + n; /* adjust frame top */ lua_unlock(L); -- cgit v1.2.3-55-g6feb