lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Both, actually, depending on your point of view: If the table had ten or
more elements, 10 would be a valid index; likewise, if the index was 1,
a table with a single element would suffice.

TL;DR: Not a bug IMO, both are fine.

On 07.09.22 16:59, Alexander Chernoskutov wrote:
Hi!

I found a minor bug in error message of table.remove().

If you do

> a = {1}
> table.remove(a, 10)

you get

> stdin:1: bad argument #1 to 'remove' (position out of bounds)

But 'bad argument' is actually #2, not #1.

A possible fix

Commit: 997f11f54322883c3181225f29d101a597f31730


--- a/ltablib.c
+++ b/ltablib.c
@@ -93,7 +93,7 @@ static int tremove (lua_State *L) {
   lua_Integer pos = luaL_optinteger(L, 2, size);
   if (pos != size)  /* validate 'pos' if given */
     /* check whether 'pos' is in [1, size + 1] */
-    luaL_argcheck(L, (lua_Unsigned)pos - 1u <= (lua_Unsigned)size, 1,
+    luaL_argcheck(L, (lua_Unsigned)pos - 1u <= (lua_Unsigned)size, 2,
                      "position out of bounds");
   lua_geti(L, 1, pos);  /* result = t[pos] */
   for ( ; pos < size; pos++) {