summaryrefslogtreecommitdiff
path: root/lstring.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-12-07 16:59:52 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-12-07 16:59:52 -0200
commit76223730332cbda5d47c09f019ce721b91bd5be2 (patch)
tree375c159891df5faf827dde4175ce42b7aa503194 /lstring.c
parent46bc7f2bf7cf7f48c354fde6b9571b795bdd5b4d (diff)
downloadlua-github-76223730332cbda5d47c09f019ce721b91bd5be2.tar.gz
using explicit tests for allocation overflow whenever possible
Diffstat (limited to 'lstring.c')
-rw-r--r--lstring.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/lstring.c b/lstring.c
index e8f6f5c9..1b3f53e1 100644
--- a/lstring.c
+++ b/lstring.c
@@ -1,5 +1,5 @@
/*
-** $Id: lstring.c,v 2.57 2017/07/27 13:50:16 roberto Exp roberto $
+** $Id: lstring.c,v 2.58 2017/12/01 16:40:29 roberto Exp roberto $
** String table (keeps all strings handled by Lua)
** See Copyright Notice in lua.h
*/
@@ -31,6 +31,13 @@
#endif
+
+/*
+** Maximum size for string table.
+*/
+#define MAXSTRTB cast_int(luaM_limitN(MAX_INT, TString*))
+
+
/*
** equality for long strings
*/
@@ -173,7 +180,8 @@ static TString *internshrstr (lua_State *L, const char *str, size_t l) {
return ts;
}
}
- if (g->strt.nuse >= g->strt.size && g->strt.size <= MAX_INT/2) {
+ if (g->strt.nuse >= g->strt.size &&
+ g->strt.size <= MAXSTRTB / 2) {
luaS_resize(L, g->strt.size * 2);
list = &g->strt.hash[lmod(h, g->strt.size)]; /* recompute with new size */
}