From f5e55be2a0ce64066c1b0554675633b92c91fafb Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 16 Jan 2025 16:25:11 -0300 Subject: Bug: Missing error status in panic function 'luaD_throw' may call 'luaE_resetthread', which returns an error code but clears 'L->status'; so, 'luaD_throw' should set that status again. --- ldo.c | 1 + ltests.c | 3 +++ testes/api.lua | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/ldo.c b/ldo.c index ea052950..958b1b7d 100644 --- a/ldo.c +++ b/ldo.c @@ -120,6 +120,7 @@ l_noret luaD_throw (lua_State *L, int errcode) { else { /* thread has no error handler */ global_State *g = G(L); errcode = luaE_resetthread(L, errcode); /* close all upvalues */ + L->status = errcode; if (g->mainthread->errorJmp) { /* main thread has a handler? */ setobjs2s(L, g->mainthread->top.p++, L->top.p - 1); /* copy error obj. */ luaD_throw(g->mainthread, errcode); /* re-throw in main thread */ diff --git a/ltests.c b/ltests.c index a27cdb07..af0f43e2 100644 --- a/ltests.c +++ b/ltests.c @@ -1655,6 +1655,9 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) { int level = getnum; luaL_traceback(L1, L1, msg, level); } + else if EQ("threadstatus") { + lua_pushstring(L1, statcodes[lua_status(L1)]); + } else if EQ("return") { int n = getnum; if (L1 != L) { diff --git a/testes/api.lua b/testes/api.lua index 752ff18f..eab3059b 100644 --- a/testes/api.lua +++ b/testes/api.lua @@ -399,6 +399,10 @@ do -- trivial error assert(T.checkpanic("pushstring hi; error") == "hi") + -- thread status inside panic (bug in 5.4.4) + assert(T.checkpanic("pushstring hi; error", "threadstatus; return 2") == + "ERRRUN") + -- using the stack inside panic assert(T.checkpanic("pushstring hi; error;", [[checkstack 5 XX -- cgit v1.2.3-55-g6feb