diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-05-20 13:14:33 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-05-20 13:14:33 -0300 |
commit | 42d40581dd919fb134c07027ca1ce0844c670daf (patch) | |
tree | 9a1037510268dc09dbedebf2a91729399bcca2e0 /ldebug.c | |
parent | e435aaabef8e717e0812a16a82b56acd11fb34c1 (diff) | |
download | lua-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.c | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -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 | ||