Skip to content

Commit 2db966f

Browse files
committed
Bug: luaL_traceback may need more than 5 stack slots
1 parent ae9a0cb commit 2db966f

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

lauxlib.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ static int pushglobalfuncname (lua_State *L, lua_Debug *ar) {
8080
int top = lua_gettop(L);
8181
lua_getinfo(L, "f", ar); /* push function */
8282
lua_getfield(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);
83+
luaL_checkstack(L, 6, "not enough stack"); /* slots for 'findfield' */
8384
if (findfield(L, top + 1, 2)) {
8485
const char *name = lua_tostring(L, -1);
8586
if (strncmp(name, LUA_GNAME ".", 3) == 0) { /* name start with '_G.'? */

ltests.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,11 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) {
16501650
int nres;
16511651
status = lua_resume(lua_tothread(L1, i), L, getnum, &nres);
16521652
}
1653+
else if EQ("traceback") {
1654+
const char *msg = getstring;
1655+
int level = getnum;
1656+
luaL_traceback(L1, L1, msg, level);
1657+
}
16531658
else if EQ("return") {
16541659
int n = getnum;
16551660
if (L1 != L) {

testes/errors.lua

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ end
9191

9292
if not T then
9393
(Message or print)
94-
('\n >>> testC not active: skipping memory message test <<<\n')
94+
('\n >>> testC not active: skipping tests for messages in C <<<\n')
9595
else
9696
print "testing memory error message"
9797
local a = {}
@@ -104,6 +104,19 @@ else
104104
end)
105105
T.totalmem(0)
106106
assert(not st and msg == "not enough" .. " memory")
107+
108+
-- stack space for luaL_traceback (bug in 5.4.6)
109+
local res = T.testC[[
110+
# push 16 elements on the stack
111+
pushnum 1; pushnum 1; pushnum 1; pushnum 1; pushnum 1;
112+
pushnum 1; pushnum 1; pushnum 1; pushnum 1; pushnum 1;
113+
pushnum 1; pushnum 1; pushnum 1; pushnum 1; pushnum 1;
114+
pushnum 1;
115+
# traceback should work with 4 remaining slots
116+
traceback xuxu 1;
117+
return 1
118+
]]
119+
assert(string.find(res, "xuxu.-main chunk"))
107120
end
108121

109122

0 commit comments

Comments
 (0)