From e663a24ab03a54fa221c20a793812e5c5ffdf94f Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 8 Dec 2017 15:28:25 -0200 Subject: more freedom in handling memory-allocation errors (not all allocations automatically raise an error), which allows fixing a bug when resizing a table. --- lstring.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lstring.c') diff --git a/lstring.c b/lstring.c index 1b3f53e1..1675b87a 100644 --- a/lstring.c +++ b/lstring.c @@ -1,5 +1,5 @@ /* -** $Id: lstring.c,v 2.58 2017/12/01 16:40:29 roberto Exp roberto $ +** $Id: lstring.c,v 2.59 2017/12/07 18:59:52 roberto Exp roberto $ ** String table (keeps all strings handled by Lua) ** See Copyright Notice in lua.h */ @@ -70,12 +70,15 @@ unsigned int luaS_hashlongstr (TString *ts) { /* -** Resizes the string table. +** Resize the string table. If allocation fails, keep the current size. +** (This can degrade performance, but any size should work correctly.) */ void luaS_resize (lua_State *L, int newsize) { int i; TString **newhash = luaM_newvector(L, newsize, TString *); stringtable *tb = &G(L)->strt; + if (newhash == NULL) /* allocation failed? */ + return; /* leave hash as it is */ for (i = 0; i < newsize; i++) /* initialize new hash array */ newhash[i] = NULL; for (i = 0; i < tb->size; i++) { /* rehash all elements into new array */ -- cgit v1.2.3-55-g6feb