diff options
Diffstat (limited to 'ltable.c')
-rw-r--r-- | ltable.c | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -48,8 +48,8 @@ | |||
48 | 48 | ||
49 | /* | 49 | /* |
50 | ** MAXASIZE is the maximum size of the array part. It is the minimum | 50 | ** MAXASIZE is the maximum size of the array part. It is the minimum |
51 | ** between 2^MAXABITS and the maximum size such that, measured in bytes, | 51 | ** between 2^MAXABITS and the maximum size that, measured in bytes, |
52 | ** it fits in a 'size_t'. | 52 | ** fits in a 'size_t'. |
53 | */ | 53 | */ |
54 | #define MAXASIZE luaM_limitN(1u << MAXABITS, TValue) | 54 | #define MAXASIZE luaM_limitN(1u << MAXABITS, TValue) |
55 | 55 | ||
@@ -269,7 +269,7 @@ static const TValue *getgeneric (Table *t, const TValue *key) { | |||
269 | ** the array part of a table, 0 otherwise. | 269 | ** the array part of a table, 0 otherwise. |
270 | */ | 270 | */ |
271 | static unsigned int arrayindex (lua_Integer k) { | 271 | static unsigned int arrayindex (lua_Integer k) { |
272 | if (0 < k && l_castS2U(k) <= MAXASIZE) | 272 | if (l_castS2U(k) - 1u < MAXASIZE) /* 'k' in [1, MAXASIZE]? */ |
273 | return cast_uint(k); /* 'key' is an appropriate array index */ | 273 | return cast_uint(k); /* 'key' is an appropriate array index */ |
274 | else | 274 | else |
275 | return 0; | 275 | return 0; |
@@ -286,7 +286,7 @@ static unsigned int findindex (lua_State *L, Table *t, TValue *key, | |||
286 | unsigned int i; | 286 | unsigned int i; |
287 | if (ttisnil(key)) return 0; /* first iteration */ | 287 | if (ttisnil(key)) return 0; /* first iteration */ |
288 | i = ttisinteger(key) ? arrayindex(ivalue(key)) : 0; | 288 | i = ttisinteger(key) ? arrayindex(ivalue(key)) : 0; |
289 | if (i != 0 && i <= asize) /* is 'key' inside array part? */ | 289 | if (i - 1u < asize) /* is 'key' inside array part? */ |
290 | return i; /* yes; that's the index */ | 290 | return i; /* yes; that's the index */ |
291 | else { | 291 | else { |
292 | const TValue *n = getgeneric(t, key); | 292 | const TValue *n = getgeneric(t, key); |
@@ -678,7 +678,7 @@ TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) { | |||
678 | ** changing the real size of the array). | 678 | ** changing the real size of the array). |
679 | */ | 679 | */ |
680 | const TValue *luaH_getint (Table *t, lua_Integer key) { | 680 | const TValue *luaH_getint (Table *t, lua_Integer key) { |
681 | if (l_castS2U(key) - 1u < t->alimit) /* (1 <= key && key <= t->alimit)? */ | 681 | if (l_castS2U(key) - 1u < t->alimit) /* 'key' in [1, t->alimit]? */ |
682 | return &t->array[key - 1]; | 682 | return &t->array[key - 1]; |
683 | else if (!limitequalsasize(t) && /* key still may be in the array part? */ | 683 | else if (!limitequalsasize(t) && /* key still may be in the array part? */ |
684 | (l_castS2U(key) == t->alimit + 1 || | 684 | (l_castS2U(key) == t->alimit + 1 || |