diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-01-25 19:51:33 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-01-25 19:51:33 -0200 |
commit | eb262bc61754670d45fb030432932c599cdef2d6 (patch) | |
tree | eafc4c8c247a6f8672b9d792e0c0bfa3f7d54563 /ltable.c | |
parent | 74907fb71e69949d63d94c4c12b80938c974a6df (diff) | |
download | lua-eb262bc61754670d45fb030432932c599cdef2d6.tar.gz lua-eb262bc61754670d45fb030432932c599cdef2d6.tar.bz2 lua-eb262bc61754670d45fb030432932c599cdef2d6.zip |
2^15 does not fit in a 16-bit int
Diffstat (limited to 'ltable.c')
-rw-r--r-- | ltable.c | 12 |
1 files changed, 5 insertions, 7 deletions
@@ -35,10 +35,10 @@ | |||
35 | /* | 35 | /* |
36 | ** max size of array part is 2^MAXBITS | 36 | ** max size of array part is 2^MAXBITS |
37 | */ | 37 | */ |
38 | #if BITS_INT > 24 | 38 | #if BITS_INT > 26 |
39 | #define MAXBITS 24 | 39 | #define MAXBITS 24 |
40 | #else | 40 | #else |
41 | #define MAXBITS (BITS_INT-1) | 41 | #define MAXBITS (BITS_INT-2) |
42 | #endif | 42 | #endif |
43 | 43 | ||
44 | /* check whether `x' < 2^MAXBITS */ | 44 | /* check whether `x' < 2^MAXBITS */ |
@@ -140,9 +140,9 @@ int luaH_nexti (Table *t, int i, TObject *where) { | |||
140 | static void computesizes (int nums[], int ntotal, int *narray, int *nhash) { | 140 | static void computesizes (int nums[], int ntotal, int *narray, int *nhash) { |
141 | int n = 0; /* (log of) optimal size for array part */ | 141 | int n = 0; /* (log of) optimal size for array part */ |
142 | int na = 0; /* number of elements to go to array part */ | 142 | int na = 0; /* number of elements to go to array part */ |
143 | int i=0; | 143 | int i; |
144 | int a = nums[0]; /* number of elements smaller than 2^i */ | 144 | int a = nums[0]; /* number of elements smaller than 2^i */ |
145 | while (++i <= MAXBITS && *narray >= twoto(i-1)) { | 145 | for (i = 1; i <= MAXBITS && *narray >= twoto(i-1); i++) { |
146 | if (nums[i] == 0) continue; | 146 | if (nums[i] == 0) continue; |
147 | a += nums[i]; | 147 | a += nums[i]; |
148 | if (a >= twoto(i-1)) { /* more than half elements in use? */ | 148 | if (a >= twoto(i-1)) { /* more than half elements in use? */ |
@@ -152,7 +152,7 @@ static void computesizes (int nums[], int ntotal, int *narray, int *nhash) { | |||
152 | } | 152 | } |
153 | lua_assert(na <= *narray && *narray <= ntotal); | 153 | lua_assert(na <= *narray && *narray <= ntotal); |
154 | *nhash = ntotal - na; | 154 | *nhash = ntotal - na; |
155 | *narray = (n == 0) ? 0 : (1<<n); | 155 | *narray = (n == 0) ? 0 : twoto(n); |
156 | lua_assert(na <= *narray && na >= *narray/2); | 156 | lua_assert(na <= *narray && na >= *narray/2); |
157 | } | 157 | } |
158 | 158 | ||
@@ -199,8 +199,6 @@ static void numuse (const Table *t, int *narray, int *nhash) { | |||
199 | 199 | ||
200 | static void setarrayvector (lua_State *L, Table *t, int size) { | 200 | static void setarrayvector (lua_State *L, Table *t, int size) { |
201 | int i; | 201 | int i; |
202 | if (size > twoto(MAXBITS)) | ||
203 | luaD_error(L, "table overflow"); | ||
204 | luaM_reallocvector(L, t->array, t->sizearray, size, TObject); | 202 | luaM_reallocvector(L, t->array, t->sizearray, size, TObject); |
205 | for (i=t->sizearray; i<size; i++) | 203 | for (i=t->sizearray; i<size; i++) |
206 | setnilvalue(&t->array[i]); | 204 | setnilvalue(&t->array[i]); |