diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-12-07 16:59:52 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-12-07 16:59:52 -0200 |
| commit | 76223730332cbda5d47c09f019ce721b91bd5be2 (patch) | |
| tree | 375c159891df5faf827dde4175ce42b7aa503194 /lstring.c | |
| parent | 46bc7f2bf7cf7f48c354fde6b9571b795bdd5b4d (diff) | |
| download | lua-76223730332cbda5d47c09f019ce721b91bd5be2.tar.gz lua-76223730332cbda5d47c09f019ce721b91bd5be2.tar.bz2 lua-76223730332cbda5d47c09f019ce721b91bd5be2.zip | |
using explicit tests for allocation overflow whenever possible
Diffstat (limited to 'lstring.c')
| -rw-r--r-- | lstring.c | 12 |
1 files changed, 10 insertions, 2 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstring.c,v 2.57 2017/07/27 13:50:16 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 2.58 2017/12/01 16:40:29 roberto Exp roberto $ |
| 3 | ** String table (keeps all strings handled by Lua) | 3 | ** String table (keeps all strings handled by Lua) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -31,6 +31,13 @@ | |||
| 31 | #endif | 31 | #endif |
| 32 | 32 | ||
| 33 | 33 | ||
| 34 | |||
| 35 | /* | ||
| 36 | ** Maximum size for string table. | ||
| 37 | */ | ||
| 38 | #define MAXSTRTB cast_int(luaM_limitN(MAX_INT, TString*)) | ||
| 39 | |||
| 40 | |||
| 34 | /* | 41 | /* |
| 35 | ** equality for long strings | 42 | ** equality for long strings |
| 36 | */ | 43 | */ |
| @@ -173,7 +180,8 @@ static TString *internshrstr (lua_State *L, const char *str, size_t l) { | |||
| 173 | return ts; | 180 | return ts; |
| 174 | } | 181 | } |
| 175 | } | 182 | } |
| 176 | if (g->strt.nuse >= g->strt.size && g->strt.size <= MAX_INT/2) { | 183 | if (g->strt.nuse >= g->strt.size && |
| 184 | g->strt.size <= MAXSTRTB / 2) { | ||
| 177 | luaS_resize(L, g->strt.size * 2); | 185 | luaS_resize(L, g->strt.size * 2); |
| 178 | list = &g->strt.hash[lmod(h, g->strt.size)]; /* recompute with new size */ | 186 | list = &g->strt.hash[lmod(h, g->strt.size)]; /* recompute with new size */ |
| 179 | } | 187 | } |
