Fix reporting of an error during error handling.

Reported by Sergey Kaplun. #1381
This commit is contained in:
Mike Pall
2025-10-16 13:11:02 +02:00
parent 871db2c84e
commit 54a162688e
2 changed files with 11 additions and 0 deletions

View File

@@ -803,9 +803,17 @@ LJ_NOINLINE GCstr *lj_err_str(lua_State *L, ErrMsg em)
return lj_str_newz(L, err2msg(em));
}
LJ_NORET LJ_NOINLINE static void lj_err_err(lua_State *L)
{
setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRERR));
lj_err_throw(L, LUA_ERRERR);
}
/* Out-of-memory error. */
LJ_NOINLINE void lj_err_mem(lua_State *L)
{
if (L->status == LUA_ERRERR)
lj_err_err(L);
if (L->status == LUA_ERRERR+1) /* Don't touch the stack during lua_open. */
lj_vm_unwind_c(L->cframe, LUA_ERRMEM);
if (LJ_HASJIT) {
@@ -902,6 +910,8 @@ LJ_NOINLINE void LJ_FASTCALL lj_err_run(lua_State *L)
/* Stack overflow error. */
void LJ_FASTCALL lj_err_stkov(lua_State *L)
{
if (L->status == LUA_ERRERR)
lj_err_err(L);
lj_debug_addloc(L, err2msg(LJ_ERR_STKOV), L->base-1, NULL);
lj_err_run(L);
}

View File

@@ -195,6 +195,7 @@ static TValue *cpluaopen(lua_State *L, lua_CFunction dummy, void *ud)
lj_meta_init(L);
lj_lex_init(L);
fixstring(lj_err_str(L, LJ_ERR_ERRMEM)); /* Preallocate memory error msg. */
fixstring(lj_err_str(L, LJ_ERR_ERRERR)); /* Preallocate err in err msg. */
g->gc.threshold = 4*g->gc.total;
#if LJ_HASFFI
lj_ctype_initfin(L);