New macro 'pushvfstring'

Helps to ensure that 'luaO_pushvfstring' is being called correctly,
with an error check after closing the vararg list with 'va_end'.
This commit is contained in:
Roberto Ierusalimschy
2025-04-23 11:55:04 -03:00
parent 9b014d4bcd
commit e055905914
4 changed files with 13 additions and 16 deletions

View File

@@ -43,11 +43,7 @@ static int codesJ (FuncState *fs, OpCode o, int sj, int k);
l_noret luaK_semerror (LexState *ls, const char *fmt, ...) {
const char *msg;
va_list argp;
va_start(argp, fmt);
msg = luaO_pushvfstring(ls->L, fmt, argp);
va_end(argp);
if (msg == NULL) /* error? */
luaD_throw(ls->L, LUA_ERRMEM);
pushvfstring(ls->L, argp, fmt, msg);
ls->t.token = 0; /* remove "near <token>" from final message */
luaX_syntaxerror(ls, msg);
}