aboutsummaryrefslogtreecommitdiff
path: root/ltablib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-02-07 13:39:54 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-02-07 13:39:54 -0300
commit0c9bec0d38ed3d2c45d7be4e764a0bcffef98be1 (patch)
tree05fd1ba56705dc0a1728e1bedda7961cc96414c1 /ltablib.c
parentc31d6774ac7db4cfbc548ce507ae65ab6036f873 (diff)
downloadlua-0c9bec0d38ed3d2c45d7be4e764a0bcffef98be1.tar.gz
lua-0c9bec0d38ed3d2c45d7be4e764a0bcffef98be1.tar.bz2
lua-0c9bec0d38ed3d2c45d7be4e764a0bcffef98be1.zip
Better handling of size limit when resizing a table
Avoid silent conversions from int to unsigned int when calling 'luaH_resize'; avoid silent conversions from lua_Integer to int in 'table.create'; MAXASIZE corrected for the new implementation of arrays; 'luaH_resize' checks explicitly whether new size respects MAXASIZE. (Even constructors were bypassing that check.)
Diffstat (limited to 'ltablib.c')
-rw-r--r--ltablib.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/ltablib.c b/ltablib.c
index c8838963..2ba31a4f 100644
--- a/ltablib.c
+++ b/ltablib.c
@@ -59,8 +59,10 @@ static void checktab (lua_State *L, int arg, int what) {
59 59
60 60
61static int tcreate (lua_State *L) { 61static int tcreate (lua_State *L) {
62 int sizeseq = (int)luaL_checkinteger(L, 1); 62 lua_Unsigned sizeseq = (lua_Unsigned)luaL_checkinteger(L, 1);
63 int sizerest = (int)luaL_optinteger(L, 2, 0); 63 lua_Unsigned sizerest = (lua_Unsigned)luaL_optinteger(L, 2, 0);
64 luaL_argcheck(L, sizeseq <= UINT_MAX, 1, "out of range");
65 luaL_argcheck(L, sizerest <= UINT_MAX, 2, "out of range");
64 lua_createtable(L, sizeseq, sizerest); 66 lua_createtable(L, sizeseq, sizerest);
65 return 1; 67 return 1;
66} 68}