Cleanup stack overflow handling.

Reported by Peter Cawley. #962
This commit is contained in:
Mike Pall 2023-09-21 01:58:43 +02:00
parent 9760984638
commit d2f6c55b05

View File

@ -97,8 +97,17 @@ void lj_state_shrinkstack(lua_State *L, MSize used)
void LJ_FASTCALL lj_state_growstack(lua_State *L, MSize need) void LJ_FASTCALL lj_state_growstack(lua_State *L, MSize need)
{ {
MSize n; MSize n;
if (L->stacksize > LJ_STACK_MAXEX) /* Overflow while handling overflow? */ if (L->stacksize >= LJ_STACK_MAXEX) {
lj_err_throw(L, LUA_ERRERR); /* 4. Throw 'error in error handling' when we are _over_ the limit. */
if (L->stacksize > LJ_STACK_MAXEX)
lj_err_throw(L, LUA_ERRERR); /* Does not invoke an error handler. */
/* 1. We are _at_ the limit after the last growth. */
if (!L->status) { /* 2. Throw 'stack overflow'. */
L->status = LUA_ERRRUN; /* Prevent ending here again for pushed msg. */
lj_err_msg(L, LJ_ERR_STKOV); /* May invoke an error handler. */
}
/* 3. Add space (over the limit) for pushed message and error handler. */
}
n = L->stacksize + need; n = L->stacksize + need;
if (n > LJ_STACK_MAX) { if (n > LJ_STACK_MAX) {
n += 2*LUA_MINSTACK; n += 2*LUA_MINSTACK;
@ -108,8 +117,6 @@ void LJ_FASTCALL lj_state_growstack(lua_State *L, MSize need)
n = LJ_STACK_MAX; n = LJ_STACK_MAX;
} }
resizestack(L, n); resizestack(L, n);
if (L->stacksize >= LJ_STACK_MAXEX)
lj_err_msg(L, LJ_ERR_STKOV);
} }
void LJ_FASTCALL lj_state_growstack1(lua_State *L) void LJ_FASTCALL lj_state_growstack1(lua_State *L)