diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2007-11-26 14:57:33 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2007-11-26 14:57:33 -0200 |
| commit | 9f0d62ad9f7ace2c92bbdf11a8d0fb908f6feb1c (patch) | |
| tree | f5ea3094474861ea468ac771f0efc6891f0f9b78 /ltablib.c | |
| parent | 64ecf2421089d1f1c83fdec99901699797bd43fb (diff) | |
| download | lua-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.c | 5 |
1 files changed, 3 insertions, 2 deletions
| @@ -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) { | |||
| 110 | static int tremove (lua_State *L) { | 110 | static 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); |
