Skip to content

fix(code/vendor/lua/src): Save stack space while handling errors #3380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion code/vendor/lua/src/ldebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,11 @@ 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 (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);
}

Expand Down
6 changes: 4 additions & 2 deletions code/vendor/lua/src/lvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,8 +698,10 @@ void luaV_concat (lua_State *L, int total) {
/* collect total length */
for (i = 1; i < total && tostring(L, top-i-1); i++) {
size_t l = vslen(top - i - 1);
if (l >= (MAX_SIZE/sizeof(char)) - tl)
if (l >= (MAX_SIZE/sizeof(char)) - tl) {
L->top = top - total; /* pop strings to avoid wasting stack */
luaG_runerror(L, "string length overflow");
}
tl += l;
}
buffer = luaZ_openspace(L, &G(L)->buff, tl);
Expand All @@ -713,7 +715,7 @@ void luaV_concat (lua_State *L, int total) {
setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl)); /* create result */
}
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 */
}

Expand Down
Loading