diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-12-08 15:28:25 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-12-08 15:28:25 -0200 |
commit | e663a24ab03a54fa221c20a793812e5c5ffdf94f (patch) | |
tree | 8fbd40f779f0eed29d46f26c07e1234fd5df8bae /lstring.c | |
parent | 40f823ec907fd725617e37199199b3ed424bd88c (diff) | |
download | lua-e663a24ab03a54fa221c20a793812e5c5ffdf94f.tar.gz lua-e663a24ab03a54fa221c20a793812e5c5ffdf94f.tar.bz2 lua-e663a24ab03a54fa221c20a793812e5c5ffdf94f.zip |
more freedom in handling memory-allocation errors (not all allocations
automatically raise an error), which allows fixing a bug when resizing
a table.
Diffstat (limited to 'lstring.c')
-rw-r--r-- | lstring.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.c,v 2.58 2017/12/01 16:40:29 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 2.59 2017/12/07 18:59:52 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 | */ |
@@ -70,12 +70,15 @@ unsigned int luaS_hashlongstr (TString *ts) { | |||
70 | 70 | ||
71 | 71 | ||
72 | /* | 72 | /* |
73 | ** Resizes the string table. | 73 | ** Resize the string table. If allocation fails, keep the current size. |
74 | ** (This can degrade performance, but any size should work correctly.) | ||
74 | */ | 75 | */ |
75 | void luaS_resize (lua_State *L, int newsize) { | 76 | void luaS_resize (lua_State *L, int newsize) { |
76 | int i; | 77 | int i; |
77 | TString **newhash = luaM_newvector(L, newsize, TString *); | 78 | TString **newhash = luaM_newvector(L, newsize, TString *); |
78 | stringtable *tb = &G(L)->strt; | 79 | stringtable *tb = &G(L)->strt; |
80 | if (newhash == NULL) /* allocation failed? */ | ||
81 | return; /* leave hash as it is */ | ||
79 | for (i = 0; i < newsize; i++) /* initialize new hash array */ | 82 | for (i = 0; i < newsize; i++) /* initialize new hash array */ |
80 | newhash[i] = NULL; | 83 | newhash[i] = NULL; |
81 | for (i = 0; i < tb->size; i++) { /* rehash all elements into new array */ | 84 | for (i = 0; i < tb->size; i++) { /* rehash all elements into new array */ |