aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-10-13 16:07:40 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-10-13 16:07:40 -0300
commitb114c99a60cd87f7a7b2e5608b9492235b499d80 (patch)
treea1c2766a58426db7e68bbf34999ece0aed471384
parent916587508c117decb2f4d70677fa06be18803874 (diff)
downloadlua-b114c99a60cd87f7a7b2e5608b9492235b499d80.tar.gz
lua-b114c99a60cd87f7a7b2e5608b9492235b499d80.tar.bz2
lua-b114c99a60cd87f7a7b2e5608b9492235b499d80.zip
two small bugs: 'debug.getinfo' did not consider negative indices as out
of range + 'debug.[gs]etlocal' crash on tail calls
-rw-r--r--ldebug.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/ldebug.c b/ldebug.c
index 80d367cd..dd6f67a6 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 2.55 2009/09/28 12:37:17 roberto Exp roberto $ 2** $Id: ldebug.c,v 2.56 2009/09/28 16:32:50 roberto Exp roberto $
3** Debug Interface 3** Debug Interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -93,9 +93,12 @@ LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {
93 status = 1; 93 status = 1;
94 ar->i_ci = ci; 94 ar->i_ci = ci;
95 } 95 }
96 else if (level < 0) { /* level is of a lost tail call? */ 96 else if (level < 0) {
97 status = 1; 97 if (ci == L->ci) status = 0; /* level was negative? */
98 ar->i_ci = NULL; 98 else { /* level is of a lost tail call */
99 status = 1;
100 ar->i_ci = NULL;
101 }
99 } 102 }
100 else status = 0; /* no such level */ 103 else status = 0; /* no such level */
101 lua_unlock(L); 104 lua_unlock(L);
@@ -107,6 +110,7 @@ static const char *findlocal (lua_State *L, CallInfo *ci, int n,
107 StkId *pos) { 110 StkId *pos) {
108 const char *name = NULL; 111 const char *name = NULL;
109 StkId base; 112 StkId base;
113 if (ci == NULL) return NULL; /* tail call? */
110 if (isLua(ci)) { 114 if (isLua(ci)) {
111 base = ci->u.l.base; 115 base = ci->u.l.base;
112 name = luaF_getlocalname(ci_func(ci)->l.p, n, currentpc(ci)); 116 name = luaF_getlocalname(ci_func(ci)->l.p, n, currentpc(ci));
@@ -125,9 +129,8 @@ static const char *findlocal (lua_State *L, CallInfo *ci, int n,
125 129
126 130
127LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { 131LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
128 CallInfo *ci = ar->i_ci;
129 StkId pos; 132 StkId pos;
130 const char *name = findlocal(L, ci, n, &pos); 133 const char *name = findlocal(L, ar->i_ci, n, &pos);
131 lua_lock(L); 134 lua_lock(L);
132 if (name) { 135 if (name) {
133 setobj2s(L, L->top, pos); 136 setobj2s(L, L->top, pos);
@@ -139,9 +142,8 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
139 142
140 143
141LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { 144LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
142 CallInfo *ci = ar->i_ci;
143 StkId pos; 145 StkId pos;
144 const char *name = findlocal(L, ci, n, &pos); 146 const char *name = findlocal(L, ar->i_ci, n, &pos);
145 lua_lock(L); 147 lua_lock(L);
146 if (name) 148 if (name)
147 setobjs2s(L, pos, L->top - 1); 149 setobjs2s(L, pos, L->top - 1);