Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/mit/lua/dist/src Apply bugfix #7 from lua.org/bugs....
details: https://anonhg.NetBSD.org/src/rev/09661948e040
branches: trunk
changeset: 991180:09661948e040
user: mbalmer <mbalmer%NetBSD.org@localhost>
date: Sun Jul 01 10:08:38 2018 +0000
description:
Apply bugfix #7 from lua.org/bugs.html: Memory-allocation error when resizing
a table can leave it in an inconsistent state.
diffstat:
external/mit/lua/dist/src/ltable.c | 21 +++++++++++++++++++--
1 files changed, 19 insertions(+), 2 deletions(-)
diffs (45 lines):
diff -r 80d81a27a288 -r 09661948e040 external/mit/lua/dist/src/ltable.c
--- a/external/mit/lua/dist/src/ltable.c Sun Jul 01 09:53:54 2018 +0000
+++ b/external/mit/lua/dist/src/ltable.c Sun Jul 01 10:08:38 2018 +0000
@@ -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 @@
}
+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 */
Home |
Main Index |
Thread Index |
Old Index