Encoding of table indices (hres) must use C indices

As the encoding of array indices is (~index), 0 is encoded as -1 and
INT_MAX is encoded as INT_MIN.
This commit is contained in:
Roberto Ierusalimschy
2024-06-10 12:09:35 -03:00
parent bdc85357aa
commit 94b503d95e
4 changed files with 30 additions and 24 deletions

View File

@@ -365,7 +365,7 @@ static void checktable (global_State *g, Table *h) {
checkobjrefN(g, hgc, h->metatable);
for (i = 0; i < asize; i++) {
TValue aux;
arr2obj(h, i + 1, &aux);
arr2obj(h, i, &aux);
checkvalref(g, hgc, &aux);
}
for (n = gnode(h, 0); n < limit; n++) {
@@ -1010,7 +1010,7 @@ static int table_query (lua_State *L) {
}
else if (cast_uint(i) < asize) {
lua_pushinteger(L, i);
arr2obj(t, i + 1, s2v(L->top.p));
arr2obj(t, i, s2v(L->top.p));
api_incr_top(L);
lua_pushnil(L);
}