From ee99452158de5e2fa804bd10de7669848f3b3952 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 28 Feb 2025 14:53:58 -0300 Subject: Error object cannot be nil Lua will change a nil as error object to a string message, so that it never reports an error with nil as the error object. --- ldo.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'ldo.c') diff --git a/ldo.c b/ldo.c index 3ddc5a4c..84f7bbb2 100644 --- a/ldo.c +++ b/ldo.c @@ -112,12 +112,16 @@ void luaD_seterrorobj (lua_State *L, TStatus errcode, StkId oldtop) { break; } default: { - lua_assert(errorstatus(errcode)); /* real error */ - setobjs2s(L, oldtop, L->top.p - 1); /* error message on current top */ + lua_assert(errorstatus(errcode)); /* must be a real error */ + if (!ttisnil(s2v(L->top.p - 1))) { /* error object is not nil? */ + setobjs2s(L, oldtop, L->top.p - 1); /* move it to 'oldtop' */ + } + else /* change it to a proper message */ + setsvalue2s(L, oldtop, luaS_newliteral(L, "")); break; } } - L->top.p = oldtop + 1; + L->top.p = oldtop + 1; /* top goes back to old top plus error object */ } -- cgit v1.2.3-55-g6feb