diff options
author | pixel <pixel> | 2008-02-18 10:15:45 +0000 |
---|---|---|
committer | pixel <pixel> | 2008-02-18 10:15:45 +0000 |
commit | 11d24fff6bbda7fd295b035d79da9f29725f0e1f (patch) | |
tree | 7bd713e6d3efeecdf813d4889fd488ad137bb143 /lib/lua | |
parent | ca1522e3cb60c8f45483be92af19982ded77676d (diff) |
Patching latests lua bug reports.
Diffstat (limited to 'lib/lua')
-rw-r--r-- | lib/lua/include/luaconf.h | 8 | ||||
-rw-r--r-- | lib/lua/src/LuaLib/lbaselib.c | 12 | ||||
-rw-r--r-- | lib/lua/src/lapi.c | 9 |
3 files changed, 15 insertions, 14 deletions
diff --git a/lib/lua/include/luaconf.h b/lib/lua/include/luaconf.h index 1ada33c..edab3d1 100644 --- a/lib/lua/include/luaconf.h +++ b/lib/lua/include/luaconf.h @@ -1,5 +1,5 @@ /* -** $Id: luaconf.h,v 1.2 2008-02-17 00:35:20 pixel Exp $ +** $Id: luaconf.h,v 1.3 2008-02-18 10:15:45 pixel Exp $ ** Configuration file for Lua ** See Copyright Notice in lua.h */ @@ -440,10 +440,10 @@ @* can use. ** CHANGE it if you need lots of (Lua) stack space for your C ** functions. This limit is arbitrary; its only purpose is to stop C -** functions to consume unlimited stack space. +** functions to consume unlimited stack space. (must be smaller than +** -LUA_REGISTRYINDEX) */ -#define LUAI_MCS_AUX ((int)(INT_MAX / (4*sizeof(LUA_NUMBER)))) -#define LUAI_MAXCSTACK (LUAI_MCS_AUX > SHRT_MAX ? SHRT_MAX : LUAI_MCS_AUX) +#define LUAI_MAXCSTACK 8000 diff --git a/lib/lua/src/LuaLib/lbaselib.c b/lib/lua/src/LuaLib/lbaselib.c index 7159a68..5052148 100644 --- a/lib/lua/src/LuaLib/lbaselib.c +++ b/lib/lua/src/LuaLib/lbaselib.c @@ -1,5 +1,5 @@ /* -** $Id: lbaselib.c,v 1.9 2008-02-17 00:35:21 pixel Exp $ +** $Id: lbaselib.c,v 1.10 2008-02-18 10:15:45 pixel Exp $ ** Basic library ** See Copyright Notice in lua.h */ @@ -344,10 +344,12 @@ static int luaB_unpack (lua_State *L) { luaL_checktype(L, 1, LUA_TTABLE); i = luaL_optint(L, 2, 1); e = luaL_opt(L, luaL_checkint, 3, luaL_getn(L, 1)); + if (i > e) return 0; /* empty range */ n = e - i + 1; /* number of elements */ - if (n <= 0) return 0; /* empty range */ - luaL_checkstack(L, n, "table too big to unpack"); - for (; i<=e; i++) /* push arg[i...e] */ + if (n <= 0 || !lua_checkstack(L, n)) /* n <= 0 means arith. overflow */ + return luaL_error(L, "too many results to unpack"); + lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */ + while (i++ < e) /* push arg[i + 1...e] */ lua_rawgeti(L, 1, i); return n; } @@ -526,7 +528,7 @@ static int auxresume (lua_State *L, lua_State *co, int narg) { status = lua_resume(co, narg); if (status == 0 || status == LUA_YIELD) { int nres = lua_gettop(co); - if (!lua_checkstack(L, nres)) + if (!lua_checkstack(L, nres + 1)) luaL_error(L, "too many results to resume"); lua_xmove(co, L, nres); /* move yielded values */ return nres; diff --git a/lib/lua/src/lapi.c b/lib/lua/src/lapi.c index 849c724..32421e3 100644 --- a/lib/lua/src/lapi.c +++ b/lib/lua/src/lapi.c @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 1.7 2008-02-17 00:35:20 pixel Exp $ +** $Id: lapi.c,v 1.8 2008-02-18 10:15:45 pixel Exp $ ** Lua API ** See Copyright Notice in lua.h */ @@ -93,15 +93,14 @@ void luaA_pushobject (lua_State *L, const TValue *o) { LUA_API int lua_checkstack (lua_State *L, int size) { - int res; + int res = 1; lua_lock(L); - if ((L->top - L->base + size) > LUAI_MAXCSTACK) + if (size > LUAI_MAXCSTACK || (L->top - L->base + size) > LUAI_MAXCSTACK) res = 0; /* stack overflow */ - else { + else if (size > 0) { luaD_checkstack(L, size); if (L->ci->top < L->top + size) L->ci->top = L->top + size; - res = 1; } lua_unlock(L); return res; |