Module Name: src Committed By: mbalmer Date: Sun Jul 1 10:08:38 UTC 2018
Modified Files: src/external/mit/lua/dist/src: ltable.c Log Message: Apply bugfix #7 from lua.org/bugs.html: Memory-allocation error when resizing a table can leave it in an inconsistent state. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/external/mit/lua/dist/src/ltable.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/external/mit/lua/dist/src/ltable.c diff -u src/external/mit/lua/dist/src/ltable.c:1.9 src/external/mit/lua/dist/src/ltable.c:1.10 --- src/external/mit/lua/dist/src/ltable.c:1.9 Wed Apr 26 13:17:33 2017 +++ src/external/mit/lua/dist/src/ltable.c Sun Jul 1 10:08:38 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: ltable.c,v 1.9 2017/04/26 13:17:33 mbalmer Exp $ */ +/* $NetBSD: ltable.c,v 1.10 2018/07/01 10:08:38 mbalmer Exp $ */ /* ** Id: ltable.c,v 2.118 2016/11/07 12:38:35 roberto Exp @@ -338,17 +338,34 @@ static void setnodevector (lua_State *L, } +typedef struct { + Table *t; + unsigned int nhsize; +} AuxsetnodeT; + + +static void auxsetnode (lua_State *L, void *ud) { + AuxsetnodeT *asn = cast(AuxsetnodeT *, ud); + setnodevector(L, asn->t, asn->nhsize); +} + + void luaH_resize (lua_State *L, Table *t, unsigned int nasize, unsigned int nhsize) { unsigned int i; int j; + AuxsetnodeT asn; unsigned int oldasize = t->sizearray; int oldhsize = allocsizenode(t); Node *nold = t->node; /* save old hash ... */ if (nasize > oldasize) /* array part must grow? */ setarrayvector(L, t, nasize); /* create new hash part with appropriate size */ - setnodevector(L, t, nhsize); + asn.t = t; asn.nhsize = nhsize; + if (luaD_rawrunprotected(L, auxsetnode, &asn) != LUA_OK) { /* mem. error? */ + setarrayvector(L, t, oldasize); /* array back to its original size */ + luaD_throw(L, LUA_ERRMEM); /* rethrow memory error */ + } if (nasize < oldasize) { /* array part must shrink? */ t->sizearray = nasize; /* re-insert elements from vanishing slice */