diff options
Diffstat (limited to 'ltable.c')
-rw-r--r-- | ltable.c | 17 |
1 files changed, 13 insertions, 4 deletions
@@ -61,18 +61,25 @@ typedef union { | |||
61 | 61 | ||
62 | 62 | ||
63 | /* | 63 | /* |
64 | ** MAXABITS is the largest integer such that MAXASIZE fits in an | 64 | ** MAXABITS is the largest integer such that 2^MAXABITS fits in an |
65 | ** unsigned int. | 65 | ** unsigned int. |
66 | */ | 66 | */ |
67 | #define MAXABITS cast_int(sizeof(int) * CHAR_BIT - 1) | 67 | #define MAXABITS cast_int(sizeof(int) * CHAR_BIT - 1) |
68 | 68 | ||
69 | 69 | ||
70 | /* | 70 | /* |
71 | ** MAXASIZEB is the maximum number of elements in the array part such | ||
72 | ** that the size of the array fits in 'size_t'. | ||
73 | */ | ||
74 | #define MAXASIZEB ((MAX_SIZET/sizeof(ArrayCell)) * NM) | ||
75 | |||
76 | |||
77 | /* | ||
71 | ** MAXASIZE is the maximum size of the array part. It is the minimum | 78 | ** MAXASIZE is the maximum size of the array part. It is the minimum |
72 | ** between 2^MAXABITS and the maximum size that, measured in bytes, | 79 | ** between 2^MAXABITS and MAXASIZEB. |
73 | ** fits in a 'size_t'. | ||
74 | */ | 80 | */ |
75 | #define MAXASIZE luaM_limitN(1u << MAXABITS, TValue) | 81 | #define MAXASIZE \ |
82 | (((1u << MAXABITS) < MAXASIZEB) ? (1u << MAXABITS) : cast_uint(MAXASIZEB)) | ||
76 | 83 | ||
77 | /* | 84 | /* |
78 | ** MAXHBITS is the largest integer such that 2^MAXHBITS fits in a | 85 | ** MAXHBITS is the largest integer such that 2^MAXHBITS fits in a |
@@ -663,6 +670,8 @@ void luaH_resize (lua_State *L, Table *t, unsigned int newasize, | |||
663 | Table newt; /* to keep the new hash part */ | 670 | Table newt; /* to keep the new hash part */ |
664 | unsigned int oldasize = setlimittosize(t); | 671 | unsigned int oldasize = setlimittosize(t); |
665 | ArrayCell *newarray; | 672 | ArrayCell *newarray; |
673 | if (newasize > MAXASIZE) | ||
674 | luaG_runerror(L, "table overflow"); | ||
666 | /* create new hash part with appropriate size into 'newt' */ | 675 | /* create new hash part with appropriate size into 'newt' */ |
667 | newt.flags = 0; | 676 | newt.flags = 0; |
668 | setnodevector(L, &newt, nhsize); | 677 | setnodevector(L, &newt, nhsize); |