From 5194615c6136bf5a289312c8eaee11c771325e57 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 30 Oct 2025 15:58:03 +0100 Subject: [PATCH] consolelib: fix some early returns not properly cleaning lua stack --- src/lua_consolelib.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lua_consolelib.c b/src/lua_consolelib.c index c5b3c5139..d5ae809ae 100644 --- a/src/lua_consolelib.c +++ b/src/lua_consolelib.c @@ -154,7 +154,7 @@ void COM_Lua_f(void) { if (!splitscreen) { - lua_pop(gL, 1); // pop command info table + lua_pop(gL, 2); // pop command info table and LUA_GetErrorMessage return; // can't execute splitscreen command without player 2! } @@ -202,8 +202,10 @@ void COM_Lua_f(void) if (!lua_checkstack(gL, COM_Argc() + 1)) { CONS_Alert(CONS_WARNING, "lua command stack overflow (%d, need %s more)\n", lua_gettop(gL), sizeu1(COM_Argc() + 1)); + lua_pop(gL, 2); // pop function and LUA_GetErrorMessage return; } + LUA_PushUserdata(gL, &players[playernum], META_PLAYER); for (i = 1; i < COM_Argc(); i++) lua_pushstring(gL, COM_Argv(i)); @@ -545,6 +547,7 @@ static int lib_consPrintf(lua_State *L) if (n < 2) return luaL_error(L, "CONS_Printf requires at least two arguments: player and text."); //HUDSAFE + plr = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); if (!plr) return LUA_ErrInvalid(L, "player_t");