From 18b38ac5c74237e60a1e594bddd62ad47d6f1bb3 Mon Sep 17 00:00:00 2001 From: tg Date: Wed, 12 Nov 2008 05:45:28 +0000 Subject: [PATCH] =?UTF-8?q?if=20the=20address=20of=20bp=20changes,=20all?= =?UTF-8?q?=20backpointers=20must=20be=20adjusted=20as=20well=20=E2=98=B9?= =?UTF-8?q?=20pretty=20expensive?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aalloc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/aalloc.c b/aalloc.c index 0fc6c97..a7538cf 100644 --- a/aalloc.c +++ b/aalloc.c @@ -1,6 +1,6 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/aalloc.c,v 1.8 2008/11/12 05:40:23 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/aalloc.c,v 1.9 2008/11/12 05:45:28 tg Exp $"); /* mksh integration of aalloc */ @@ -349,6 +349,7 @@ alloc(size_t nmemb, size_t size, PArea ap) if ((bp = check_bp(ap, "alloc", 0)) == NULL) AALLOC_ABORT("cannot continue"); if (bp->last == bp->endp) { + TPtr *tp; size_t bsz; /* make room for more forward ptrs in the block allocation */ @@ -358,6 +359,12 @@ alloc(size_t nmemb, size_t size, PArea ap) bp->last = (char *)bp + (bsz / 2); bp->endp = (char *)bp + bsz; + /* all backpointers have to be adjusted */ + for (tp = (TPtr *)&bp->storage; tp < (TPtr *)bp->last; ++tp) { + tp->pv = (char *)tp; + tp->iv ^= bp->cookie; + } + /* “bp” has possibly changed, enter its new value into ap */ ap->bp.pv = (char *)bp; ap->bp.iv ^= gcookie;