aboutsummaryrefslogtreecommitdiff
path: root/ltablib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2007-11-26 14:57:33 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2007-11-26 14:57:33 -0200
commit9f0d62ad9f7ace2c92bbdf11a8d0fb908f6feb1c (patch)
treef5ea3094474861ea468ac771f0efc6891f0f9b78 /ltablib.c
parent64ecf2421089d1f1c83fdec99901699797bd43fb (diff)
downloadlua-9f0d62ad9f7ace2c92bbdf11a8d0fb908f6feb1c.tar.gz
lua-9f0d62ad9f7ace2c92bbdf11a8d0fb908f6feb1c.tar.bz2
lua-9f0d62ad9f7ace2c92bbdf11a8d0fb908f6feb1c.zip
BUG: table.remove removes last element of a table when given
an out-of-bound index
Diffstat (limited to 'ltablib.c')
-rw-r--r--ltablib.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/ltablib.c b/ltablib.c
index f7479545..437270ad 100644
--- a/ltablib.c
+++ b/ltablib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltablib.c,v 1.40 2007/06/21 13:50:53 roberto Exp roberto $ 2** $Id: ltablib.c,v 1.41 2007/09/12 20:53:24 roberto Exp roberto $
3** Library for Table Manipulation 3** Library for Table Manipulation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -110,7 +110,8 @@ static int tinsert (lua_State *L) {
110static int tremove (lua_State *L) { 110static int tremove (lua_State *L) {
111 int e = aux_getn(L, 1); 111 int e = aux_getn(L, 1);
112 int pos = luaL_optint(L, 2, e); 112 int pos = luaL_optint(L, 2, e);
113 if (e == 0) return 0; /* table is `empty' */ 113 if (!(1 <= pos && pos <= e)) /* position is outside bounds? */
114 return 0; /* nothing to remove */
114 lua_rawgeti(L, 1, pos); /* result = t[pos] */ 115 lua_rawgeti(L, 1, pos); /* result = t[pos] */
115 for ( ;pos<e; pos++) { 116 for ( ;pos<e; pos++) {
116 lua_rawgeti(L, 1, pos+1); 117 lua_rawgeti(L, 1, pos+1);