diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-11-10 15:42:04 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-11-10 15:42:04 -0200 |
commit | bfa0898312e1a36087fa10fa8020a706a2e8e885 (patch) | |
tree | 0d04ebcbce56c61dcbf2c84d14cedddd254d8fb3 | |
parent | 79b0d05480668c36e15e26ff8b8ec0e9b3c54b2b (diff) | |
download | lua-bfa0898312e1a36087fa10fa8020a706a2e8e885.tar.gz lua-bfa0898312e1a36087fa10fa8020a706a2e8e885.tar.bz2 lua-bfa0898312e1a36087fa10fa8020a706a2e8e885.zip |
bug: memory error in panic mode does not push error message on
the stack + stack check in tryfuncTM + comments
-rw-r--r-- | ldo.c | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 2.132 2014/11/02 19:19:04 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.133 2014/11/02 19:33:33 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -121,6 +121,9 @@ l_noret luaD_throw (lua_State *L, int errcode) { | |||
121 | } | 121 | } |
122 | else { /* no handler at all; abort */ | 122 | else { /* no handler at all; abort */ |
123 | if (g->panic) { /* panic function? */ | 123 | if (g->panic) { /* panic function? */ |
124 | seterrorobj(L, errcode, L->top); /* assume EXTRA_STACK */ | ||
125 | if (L->ci->top < L->top) | ||
126 | L->ci->top = L->top + 2; | ||
124 | lua_unlock(L); | 127 | lua_unlock(L); |
125 | g->panic(L); /* call it (last chance to jump out) */ | 128 | g->panic(L); /* call it (last chance to jump out) */ |
126 | } | 129 | } |
@@ -283,12 +286,21 @@ static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { | |||
283 | } | 286 | } |
284 | 287 | ||
285 | 288 | ||
289 | /* | ||
290 | ** Check whether __call metafield of 'func' is a function. If so, put | ||
291 | ** it in stack below original 'func' so that 'luaD_precall' can call | ||
292 | ** it. Raise an error if __call metafield is not a function. (The | ||
293 | ** check 'luaD_checkstack' avoids problems of errors in tag methods, | ||
294 | ** because both tag methods and error messages may need EXTRA_STACK.) | ||
295 | */ | ||
286 | static StkId tryfuncTM (lua_State *L, StkId func) { | 296 | static StkId tryfuncTM (lua_State *L, StkId func) { |
287 | const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL); | 297 | const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL); |
288 | StkId p; | 298 | StkId p; |
289 | ptrdiff_t funcr = savestack(L, func); | 299 | ptrdiff_t funcr = savestack(L, func); |
290 | if (!ttisfunction(tm)) | 300 | if (!ttisfunction(tm)) { |
301 | luaD_checkstack(L, 1); | ||
291 | luaG_typeerror(L, func, "call"); | 302 | luaG_typeerror(L, func, "call"); |
303 | } | ||
292 | /* Open a hole inside the stack at 'func' */ | 304 | /* Open a hole inside the stack at 'func' */ |
293 | for (p = L->top; p > func; p--) setobjs2s(L, p, p-1); | 305 | for (p = L->top; p > func; p--) setobjs2s(L, p, p-1); |
294 | incr_top(L); | 306 | incr_top(L); |