aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bugs25
-rw-r--r--ltablib.c5
2 files changed, 28 insertions, 2 deletions
diff --git a/bugs b/bugs
index b9015051..ed2eb666 100644
--- a/bugs
+++ b/bugs
@@ -1570,6 +1570,31 @@ lstrlib.c:
1570} 1570}
1571 1571
1572Bug{ 1572Bug{
1573what = [[table.remove removes last element of a table when given
1574an out-of-bound index]],
1575report = [[Patrick Donnelly, on 11/2007]],
1576since = [[at least 5.0]],
1577example = [[
1578a = {1,2,3}
1579table.remove(a, 4)
1580print(a[3]) --> nil (should be 3)
1581]],
1582patch = [[
1583ltablib.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
1597Bug{
1573what = [[ ]], 1598what = [[ ]],
1574report = [[ , on ]], 1599report = [[ , on ]],
1575since = [[i ]], 1600since = [[i ]],
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);