diff options
| author | Roberto I <roberto@inf.puc-rio.br> | 2026-01-04 16:39:22 -0300 |
|---|---|---|
| committer | Roberto I <roberto@inf.puc-rio.br> | 2026-01-04 16:39:22 -0300 |
| commit | 5cfc725a8b61a6f96c7324f60ac26739315095ba (patch) | |
| tree | af8c6ea8a8d2a0802603377e80f58ac34b74dff2 | |
| parent | 45c7ae5b1b05069543fe1710454c651350bc1c42 (diff) | |
| download | lua-5cfc725a8b61a6f96c7324f60ac26739315095ba.tar.gz lua-5cfc725a8b61a6f96c7324f60ac26739315095ba.tar.bz2 lua-5cfc725a8b61a6f96c7324f60ac26739315095ba.zip | |
Special case for 'string.rep' over an empty string
| -rw-r--r-- | lauxlib.h | 6 | ||||
| -rw-r--r-- | lstrlib.c | 4 |
2 files changed, 5 insertions, 5 deletions
| @@ -81,8 +81,8 @@ LUALIB_API int (luaL_checkoption) (lua_State *L, int arg, const char *def, | |||
| 81 | LUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname); | 81 | LUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname); |
| 82 | LUALIB_API int (luaL_execresult) (lua_State *L, int stat); | 82 | LUALIB_API int (luaL_execresult) (lua_State *L, int stat); |
| 83 | 83 | ||
| 84 | LUALIB_API void *luaL_alloc (void *ud, void *ptr, size_t osize, | 84 | LUALIB_API void *(luaL_alloc) (void *ud, void *ptr, size_t osize, |
| 85 | size_t nsize); | 85 | size_t nsize); |
| 86 | 86 | ||
| 87 | 87 | ||
| 88 | /* predefined references */ | 88 | /* predefined references */ |
| @@ -103,7 +103,7 @@ LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s); | |||
| 103 | 103 | ||
| 104 | LUALIB_API lua_State *(luaL_newstate) (void); | 104 | LUALIB_API lua_State *(luaL_newstate) (void); |
| 105 | 105 | ||
| 106 | LUALIB_API unsigned luaL_makeseed (lua_State *L); | 106 | LUALIB_API unsigned (luaL_makeseed) (lua_State *L); |
| 107 | 107 | ||
| 108 | LUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx); | 108 | LUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx); |
| 109 | 109 | ||
| @@ -141,8 +141,8 @@ static int str_rep (lua_State *L) { | |||
| 141 | const char *s = luaL_checklstring(L, 1, &len); | 141 | const char *s = luaL_checklstring(L, 1, &len); |
| 142 | lua_Integer n = luaL_checkinteger(L, 2); | 142 | lua_Integer n = luaL_checkinteger(L, 2); |
| 143 | const char *sep = luaL_optlstring(L, 3, "", &lsep); | 143 | const char *sep = luaL_optlstring(L, 3, "", &lsep); |
| 144 | if (n <= 0) | 144 | if (n <= 0 || (len | lsep) == 0) |
| 145 | lua_pushliteral(L, ""); | 145 | lua_pushliteral(L, ""); /* no repetitions or both strings empty */ |
| 146 | else if (l_unlikely(len > MAX_SIZE - lsep || | 146 | else if (l_unlikely(len > MAX_SIZE - lsep || |
| 147 | cast_st2S(len + lsep) > cast_st2S(MAX_SIZE) / n)) | 147 | cast_st2S(len + lsep) > cast_st2S(MAX_SIZE) / n)) |
| 148 | return luaL_error(L, "resulting string too large"); | 148 | return luaL_error(L, "resulting string too large"); |
