From 325f1045ecb174fa3cf9b80b0775311bb5bdfea0 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 19 Dec 2025 05:45:07 +0000 Subject: [PATCH] Save stack space while handling errors --- 3rdparty/lua-5.3.3/ldebug.c | 5 ++++- 3rdparty/lua-5.3.3/lvm.c | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/3rdparty/lua-5.3.3/ldebug.c b/3rdparty/lua-5.3.3/ldebug.c index 2f8694eae..9f06f7b49 100644 --- a/3rdparty/lua-5.3.3/ldebug.c +++ b/3rdparty/lua-5.3.3/ldebug.c @@ -793,8 +793,11 @@ l_noret luaG_runerror(lua_State *L, const char *fmt, ...) msg = luaO_pushvfstring(L, fmt, argp); /* format message */ va_end(argp); - if (isLua(ci)) /* if Lua function, add source:line information */ + if (isLua(ci)){ /* if Lua function, add source:line information */ luaG_addinfo(L, msg, ci_func(ci)->p->source, currentline(ci)); + setobjs2s(L, L->top - 2, L->top - 1); /* remove 'msg' from the stack */ + L->top--; + } luaG_errormsg(L); } diff --git a/3rdparty/lua-5.3.3/lvm.c b/3rdparty/lua-5.3.3/lvm.c index e95a2972c..fc51af60c 100644 --- a/3rdparty/lua-5.3.3/lvm.c +++ b/3rdparty/lua-5.3.3/lvm.c @@ -579,8 +579,10 @@ void luaV_concat(lua_State *L, int total) for (n = 1; n < total && tostring(L, top - n - 1); n++) { size_t l = vslen(top - n - 1); - if (l >= (MAX_SIZE / sizeof(char)) - tl) + if (l_unlikely(l >= (MAX_SIZE/sizeof(char)) - tl)) { + L->top = top - total; /* pop strings to avoid wasting stack */ luaG_runerror(L, "string length overflow"); + } tl += l; } @@ -598,7 +600,7 @@ void luaV_concat(lua_State *L, int total) } total -= n - 1; /* got 'n' strings to create 1 new */ - L->top -= n - 1; /* popped 'n' strings and pushed one */ + L->top = top - (n - 1); /* popped 'n' strings and pushed one */ } while (total > 1); /* repeat until only 1 result left */ }