Skip to content

Commit

Permalink
Clean up stack after script_get_backtrace (minetest#7854)
Browse files Browse the repository at this point in the history
script_get_backtrace() was leaving its return value on the stack, corrupting
subsequent lua operations for functions that did not immediately return.

This problem can specifically be observed in the case of multiple "groupcaps"
entries, each of which provides the legacy "maxwear" property.  These cause a
backtrace and thus pollute the stack for the following lua_next() call.
  • Loading branch information
mindhog authored and SmallJoker committed Nov 28, 2018
1 parent faa358e commit ddd9317
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/script/common/c_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ std::string script_get_backtrace(lua_State *L)
{
lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_BACKTRACE);
lua_call(L, 0, 1);
return luaL_checkstring(L, -1);
std::string result = luaL_checkstring(L, -1);
lua_pop(L, 1);
return result;
}

int script_exception_wrapper(lua_State *L, lua_CFunction f)
Expand Down

0 comments on commit ddd9317

Please sign in to comment.