aboutsummaryrefslogtreecommitdiff
path: root/ldebug.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-05-20 13:14:33 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-05-20 13:14:33 -0300
commit42d40581dd919fb134c07027ca1ce0844c670daf (patch)
tree9a1037510268dc09dbedebf2a91729399bcca2e0 /ldebug.c
parente435aaabef8e717e0812a16a82b56acd11fb34c1 (diff)
downloadlua-42d40581dd919fb134c07027ca1ce0844c670daf.tar.gz
lua-42d40581dd919fb134c07027ca1ce0844c670daf.tar.bz2
lua-42d40581dd919fb134c07027ca1ce0844c670daf.zip
Save stack space while handling errors
Because error handling (luaG_errormsg) uses slots from EXTRA_STACK, and some errors can recur (e.g., string overflow while creating an error message in 'luaG_runerror', or a C-stack overflow before calling the message handler), the code should use stack slots with parsimony. This commit fixes the bug "Lua-stack overflow when C stack overflows while handling an error".
Diffstat (limited to 'ldebug.c')
-rw-r--r--ldebug.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/ldebug.c b/ldebug.c
index a716d95e..fa15eaf6 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -824,8 +824,11 @@ l_noret luaG_runerror (lua_State *L, const char *fmt, ...) {
824 va_start(argp, fmt); 824 va_start(argp, fmt);
825 msg = luaO_pushvfstring(L, fmt, argp); /* format message */ 825 msg = luaO_pushvfstring(L, fmt, argp); /* format message */
826 va_end(argp); 826 va_end(argp);
827 if (isLua(ci)) /* if Lua function, add source:line information */ 827 if (isLua(ci)) { /* if Lua function, add source:line information */
828 luaG_addinfo(L, msg, ci_func(ci)->p->source, getcurrentline(ci)); 828 luaG_addinfo(L, msg, ci_func(ci)->p->source, getcurrentline(ci));
829 setobjs2s(L, L->top - 2, L->top - 1); /* remove 'msg' from the stack */
830 L->top--;
831 }
829 luaG_errormsg(L); 832 luaG_errormsg(L);
830} 833}
831 834