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.
This commit is contained in:
Roberto Ierusalimschy
2025-02-28 14:53:58 -03:00
parent 127a8e80fe
commit ee99452158
4 changed files with 23 additions and 8 deletions

View File

@@ -844,7 +844,9 @@ l_noret luaG_runerror (lua_State *L, const char *fmt, ...) {
va_start(argp, fmt);
msg = luaO_pushvfstring(L, fmt, argp); /* format message */
va_end(argp);
if (msg != NULL && isLua(ci)) { /* Lua function? (and no error) */
if (msg == NULL) /* no memory to format message? */
luaD_throw(L, LUA_ERRMEM);
else if (isLua(ci)) { /* Lua function? */
/* add source:line information */
luaG_addinfo(L, msg, ci_func(ci)->p->source, getcurrentline(ci));
setobjs2s(L, L->top.p - 2, L->top.p - 1); /* remove 'msg' */