Browse Source

calls with LUA_MULTRET may leave no free slots in the stack

Roberto Ierusalimschy 16 years ago
parent
commit
5bff2aaf47
2 changed files with 5 additions and 2 deletions
  1. 3 1
      lbaselib.c
  2. 2 1
      lua.c

+ 3 - 1
lbaselib.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lbaselib.c,v 1.215 2009/04/08 18:04:33 roberto Exp roberto $
+** $Id: lbaselib.c,v 1.216 2009/07/08 16:06:07 roberto Exp roberto $
 ** Basic library
 ** Basic library
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -419,6 +419,7 @@ static int luaB_pcall (lua_State *L) {
   int status;
   int status;
   luaL_checkany(L, 1);
   luaL_checkany(L, 1);
   status = lua_pcallk(L, lua_gettop(L) - 1, LUA_MULTRET, 0, 0, pcallcont);
   status = lua_pcallk(L, lua_gettop(L) - 1, LUA_MULTRET, 0, 0, pcallcont);
+  luaL_checkstack(L, 1, NULL);
   lua_pushboolean(L, (status == LUA_OK));
   lua_pushboolean(L, (status == LUA_OK));
   lua_insert(L, 1);
   lua_insert(L, 1);
   return lua_gettop(L);  /* return status + all results */
   return lua_gettop(L);  /* return status + all results */
@@ -434,6 +435,7 @@ static int luaB_xpcall (lua_State *L) {
   lua_replace(L, 1);
   lua_replace(L, 1);
   lua_replace(L, 2);
   lua_replace(L, 2);
   status = lua_pcallk(L, n - 2, LUA_MULTRET, 1, 1, pcallcont);
   status = lua_pcallk(L, n - 2, LUA_MULTRET, 1, 1, pcallcont);
+  luaL_checkstack(L, 1, NULL);
   lua_pushboolean(L, (status == LUA_OK));
   lua_pushboolean(L, (status == LUA_OK));
   lua_replace(L, 1);
   lua_replace(L, 1);
   return lua_gettop(L);  /* return status + all results */
   return lua_gettop(L);  /* return status + all results */

+ 2 - 1
lua.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lua.c,v 1.172 2009/02/19 17:15:35 roberto Exp roberto $
+** $Id: lua.c,v 1.173 2009/06/18 18:59:58 roberto Exp roberto $
 ** Lua stand-alone interpreter
 ** Lua stand-alone interpreter
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -218,6 +218,7 @@ static void dotty (lua_State *L) {
     if (status == LUA_OK) status = docall(L, 0, 0);
     if (status == LUA_OK) status = docall(L, 0, 0);
     report(L, status);
     report(L, status);
     if (status == LUA_OK && lua_gettop(L) > 0) {  /* any result to print? */
     if (status == LUA_OK && lua_gettop(L) > 0) {  /* any result to print? */
+      luaL_checkstack(L, LUA_MINSTACK, "too many results to print");
       lua_getglobal(L, "print");
       lua_getglobal(L, "print");
       lua_insert(L, 1);
       lua_insert(L, 1);
       if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != LUA_OK)
       if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != LUA_OK)