aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-07-15 14:26:14 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-07-15 14:26:14 -0300
commitf76f4cb79d84af4a7be9e0d75553bbe05a3ae90c (patch)
treedd9d1f8f3fb8c69f7617fe5688d7b1178bb7190e /lapi.c
parentabb85fc059a5d6427b9dc36edee1619f2c7a1da8 (diff)
downloadlua-f76f4cb79d84af4a7be9e0d75553bbe05a3ae90c.tar.gz
lua-f76f4cb79d84af4a7be9e0d75553bbe05a3ae90c.tar.bz2
lua-f76f4cb79d84af4a7be9e0d75553bbe05a3ae90c.zip
new way to control stack overflow, controling only total size of the stack
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/lapi.c b/lapi.c
index 6f33c950..1873bec3 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.83 2009/06/18 18:59:18 roberto Exp roberto $ 2** $Id: lapi.c,v 2.84 2009/06/19 14:21:23 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -86,14 +86,15 @@ LUA_API int lua_checkstack (lua_State *L, int size) {
86 int res = 1; 86 int res = 1;
87 CallInfo *ci = L->ci; 87 CallInfo *ci = L->ci;
88 lua_lock(L); 88 lua_lock(L);
89 if (size > LUAI_MAXCSTACK || 89 if (L->stack_last - L->top <= size) { /* need to grow stack? */
90 (L->top - (ci->func + 1) + size) > LUAI_MAXCSTACK) 90 int inuse = L->top - L->stack + EXTRA_STACK;
91 res = 0; /* stack overflow */ 91 if (inuse > LUAI_MAXSTACK - size) /* can grow without overflow? */
92 else if (size > 0) { 92 res = 0; /* no */
93 luaD_checkstack(L, size); 93 else
94 if (ci->top < L->top + size) 94 luaD_growstack(L, size);
95 ci->top = L->top + size;
96 } 95 }
96 if (res && ci->top < L->top + size)
97 ci->top = L->top + size; /* adjust frame top */
97 lua_unlock(L); 98 lua_unlock(L);
98 return res; 99 return res;
99} 100}