aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-03-14 15:59:21 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-03-14 15:59:21 -0300
commitc9ea94ec92a8dc02ff689aea3485c891780128b9 (patch)
tree282e5a75a262d24bfee7bb72f6bd37d47dd93d50
parentfa4b4c11009a227769499ea44bcaea295c03505f (diff)
downloadlua-c9ea94ec92a8dc02ff689aea3485c891780128b9.tar.gz
lua-c9ea94ec92a8dc02ff689aea3485c891780128b9.tar.bz2
lua-c9ea94ec92a8dc02ff689aea3485c891780128b9.zip
out-of-bound upvalues (in C) are acceptable indices
-rw-r--r--lapi.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/lapi.c b/lapi.c
index ee727c1b..d4d06777 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 1.231 2003/02/24 16:54:20 roberto Exp roberto $ 2** $Id: lapi.c,v 1.232 2003/02/27 12:33:07 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*/
@@ -56,8 +56,10 @@ static TObject *negindex (lua_State *L, int idx) {
56 default: { 56 default: {
57 TObject *func = (L->base - 1); 57 TObject *func = (L->base - 1);
58 idx = LUA_GLOBALSINDEX - idx; 58 idx = LUA_GLOBALSINDEX - idx;
59 api_check(L, iscfunction(func) && idx <= clvalue(func)->c.nupvalues); 59 lua_assert(iscfunction(func));
60 return &clvalue(func)->c.upvalue[idx-1]; 60 return (idx <= clvalue(func)->c.nupvalues)
61 ? &clvalue(func)->c.upvalue[idx-1]
62 : NULL;
61 } 63 }
62 } 64 }
63} 65}
@@ -68,8 +70,11 @@ static TObject *luaA_index (lua_State *L, int idx) {
68 api_check(L, idx <= L->top - L->base); 70 api_check(L, idx <= L->top - L->base);
69 return L->base + idx - 1; 71 return L->base + idx - 1;
70 } 72 }
71 else 73 else {
72 return negindex(L, idx); 74 TObject *o = negindex(L, idx);
75 api_check(L, o != NULL);
76 return o;
77 }
73} 78}
74 79
75 80