Skip to content

Commit

Permalink
Merge pull request #736 from mwild1/fix/balance-stack-on-uncaught-error
Browse files Browse the repository at this point in the history
luv_cfpcall: Fix stack balancing after an uncaught error
  • Loading branch information
zhaozg authored Nov 15, 2024
2 parents 1532f44 + 09a98a4 commit 353df88
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/luv.c
Original file line number Diff line number Diff line change
Expand Up @@ -715,9 +715,11 @@ LUALIB_API int luv_cfpcall(lua_State* L, int nargs, int nresult, int flags) {
case LUA_OK:
break;
case LUA_ERRMEM:
if ((flags & LUVF_CALLBACK_NOERRMSG) == 0)
if ((flags & LUVF_CALLBACK_NOERRMSG) == 0) {
fprintf(stderr, "System Error: %s\n",
luaL_tolstring(L, lua_absindex(L, -1), NULL));
lua_pop(L, 1); // Remove error string pushed by luaL_tolstring()
}
if ((flags & LUVF_CALLBACK_NOEXIT) == 0)
exit(-1);
lua_pop(L, 1);
Expand All @@ -726,9 +728,11 @@ LUALIB_API int luv_cfpcall(lua_State* L, int nargs, int nresult, int flags) {
case LUA_ERRRUN:
case LUA_ERRERR:
default:
if ((flags & LUVF_CALLBACK_NOERRMSG) == 0)
if ((flags & LUVF_CALLBACK_NOERRMSG) == 0) {
fprintf(stderr, "Uncaught Error: %s\n",
luaL_tolstring(L, lua_absindex(L, -1), NULL));
lua_pop(L, 1); // Remove error string pushed by luaL_tolstring()
}
if ((flags & LUVF_CALLBACK_NOEXIT) == 0)
exit(-1);
lua_pop(L, 1);
Expand Down

0 comments on commit 353df88

Please sign in to comment.