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 /bugs | |
| 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 'bugs')
| -rw-r--r-- | bugs | 25 |
1 files changed, 25 insertions, 0 deletions
| @@ -1570,6 +1570,31 @@ lstrlib.c: | |||
| 1570 | } | 1570 | } |
| 1571 | 1571 | ||
| 1572 | Bug{ | 1572 | Bug{ |
| 1573 | what = [[table.remove removes last element of a table when given | ||
| 1574 | an out-of-bound index]], | ||
| 1575 | report = [[Patrick Donnelly, on 11/2007]], | ||
| 1576 | since = [[at least 5.0]], | ||
| 1577 | example = [[ | ||
| 1578 | a = {1,2,3} | ||
| 1579 | table.remove(a, 4) | ||
| 1580 | print(a[3]) --> nil (should be 3) | ||
| 1581 | ]], | ||
| 1582 | patch = [[ | ||
| 1583 | ltablib.c: | ||
| 1584 | @@ -118,7 +118,8 @@ | ||
| 1585 | static int tremove (lua_State *L) { | ||
| 1586 | int e = aux_getn(L, 1); | ||
| 1587 | int pos = luaL_optint(L, 2, e); | ||
| 1588 | - if (e == 0) return 0; /* table is `empty' */ | ||
| 1589 | + if (!(1 <= pos && pos <= e)) /* position is outside bounds? */ | ||
| 1590 | + return 0; /* nothing to remove */ | ||
| 1591 | luaL_setn(L, 1, e - 1); /* t.n = n-1 */ | ||
| 1592 | lua_rawgeti(L, 1, pos); /* result = t[pos] */ | ||
| 1593 | for ( ;pos<e; pos++) { | ||
| 1594 | ]], | ||
| 1595 | } | ||
| 1596 | |||
| 1597 | Bug{ | ||
| 1573 | what = [[ ]], | 1598 | what = [[ ]], |
| 1574 | report = [[ , on ]], | 1599 | report = [[ , on ]], |
| 1575 | since = [[i ]], | 1600 | since = [[i ]], |
