diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-06-21 16:26:49 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-06-21 16:26:49 -0300 |
commit | ef28e5f789f7e7be1a3961d13cb35bbfd2542997 (patch) | |
tree | 4f254fc849428d984de947dae1bf344be674347c /lstrlib.c | |
parent | ec65ab878e04822f1cbcc3198f19076d57900e9f (diff) | |
download | lua-ef28e5f789f7e7be1a3961d13cb35bbfd2542997.tar.gz lua-ef28e5f789f7e7be1a3961d13cb35bbfd2542997.tar.bz2 lua-ef28e5f789f7e7be1a3961d13cb35bbfd2542997.zip |
Removed 'int' size limit for string.rep
Diffstat (limited to 'lstrlib.c')
-rw-r--r-- | lstrlib.c | 14 |
1 files changed, 2 insertions, 12 deletions
@@ -37,16 +37,6 @@ | |||
37 | #endif | 37 | #endif |
38 | 38 | ||
39 | 39 | ||
40 | /* | ||
41 | ** Some sizes are better limited to fit in 'int', but must also fit in | ||
42 | ** 'size_t'. (We assume that 'lua_Integer' cannot be smaller than 'int'.) | ||
43 | */ | ||
44 | #define MAXSIZE \ | ||
45 | (sizeof(size_t) < sizeof(int) ? MAX_SIZET : (size_t)(INT_MAX)) | ||
46 | |||
47 | |||
48 | |||
49 | |||
50 | static int str_len (lua_State *L) { | 40 | static int str_len (lua_State *L) { |
51 | size_t l; | 41 | size_t l; |
52 | luaL_checklstring(L, 1, &l); | 42 | luaL_checklstring(L, 1, &l); |
@@ -149,10 +139,10 @@ static int str_rep (lua_State *L) { | |||
149 | const char *sep = luaL_optlstring(L, 3, "", &lsep); | 139 | const char *sep = luaL_optlstring(L, 3, "", &lsep); |
150 | if (n <= 0) | 140 | if (n <= 0) |
151 | lua_pushliteral(L, ""); | 141 | lua_pushliteral(L, ""); |
152 | else if (l_unlikely(l + lsep < l || l + lsep > MAXSIZE / n)) | 142 | else if (l_unlikely(l + lsep < l || l + lsep > MAX_SIZE / n)) |
153 | return luaL_error(L, "resulting string too large"); | 143 | return luaL_error(L, "resulting string too large"); |
154 | else { | 144 | else { |
155 | size_t totallen = (size_t)n * l + (size_t)(n - 1) * lsep; | 145 | size_t totallen = ((size_t)n * (l + lsep)) - lsep; |
156 | luaL_Buffer b; | 146 | luaL_Buffer b; |
157 | char *p = luaL_buffinitsize(L, &b, totallen); | 147 | char *p = luaL_buffinitsize(L, &b, totallen); |
158 | while (n-- > 1) { /* first n-1 copies (followed by separator) */ | 148 | while (n-- > 1) { /* first n-1 copies (followed by separator) */ |