'luaM_shrinkvector' raises an error if it cannot shrink the block

(several parts of Lua use array size in protos as proxies for
number of valid elements)
This commit is contained in:
Roberto Ierusalimschy 2017-12-11 10:27:48 -02:00
parent e663a24ab0
commit c5ebed7399
1 changed files with 2 additions and 2 deletions

4
lmem.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lmem.c,v 1.93 2017/12/07 18:59:52 roberto Exp roberto $ ** $Id: lmem.c,v 1.94 2017/12/08 17:28:25 roberto Exp roberto $
** Interface to Memory Manager ** Interface to Memory Manager
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -89,7 +89,7 @@ void *luaM_shrinkvector_ (lua_State *L, void *block, int *size,
lua_assert(newsize <= oldsize); lua_assert(newsize <= oldsize);
newblock = (*g->frealloc)(g->ud, block, oldsize, newsize); newblock = (*g->frealloc)(g->ud, block, oldsize, newsize);
if (newblock == NULL && final_n > 0) /* allocation failed? */ if (newblock == NULL && final_n > 0) /* allocation failed? */
return block; /* keep old block */ luaM_error(L);
else { else {
g->GCdebt += newsize - oldsize; g->GCdebt += newsize - oldsize;
*size = final_n; *size = final_n;