From: ian Date: Thu, 25 Nov 2004 01:47:34 +0000 (+0000) Subject: amend seems to work X-Git-Tag: debian/1.1.1~120 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=0bcca45f296b613b1f1449d232f43eb0ada0014b;p=chiark-tcl.git amend seems to work --- diff --git a/maskmap/maskmap.c b/maskmap/maskmap.c index 77c677f..9c92810 100644 --- a/maskmap/maskmap.c +++ b/maskmap/maskmap.c @@ -26,6 +26,7 @@ static int prefix_bytes (int prefixlen) { /*---------- operations on MaskMap_Entry ----------*/ static void mme_init(MaskMap_Entry *mme) { + mme->prefixlen= -1; mme->prefix= 0; mme->data= 0; } @@ -105,11 +106,14 @@ static void mm_init(MaskMap_Value *mm) { static void mm_reallocentries(MaskMap_Value *mm, int len) { int i; MaskMap_Entry *newentries, *clear; - + + assert(len >= mm->allocd); + if (!len) return; + newentries= TREALLOC(mm->entries, sizeof(*newentries)*len); - assert(!len || newentries); + assert(newentries); - for (i=mm->allocd, clear=&mm->entries[mm->allocd]; + for (i=mm->allocd, clear=newentries+mm->allocd; i < len; i++, clear++) mme_init(clear); @@ -148,11 +152,12 @@ int do_maskmap_amend(ClientData cd, Tcl_Interp *ip, /* we're adding an entry, make room for it */ findend= mm_count(mm); - if (findend == mm->allocd) mm_reallocentries(mm, mm->allocd*2 + 1); + if (findend == mm->allocd) { + mm_reallocentries(mm, mm->allocd*2 + 1); + search= mm->entries + insertat; + } if (findend > insertat) - memmove(&mm->entries[insertat+1], - &mm->entries[insertat], - sizeof(mm->entries[0]) * (findend - insertat)); + memmove(search + 1, search, sizeof(*search) * (findend - insertat)); *search= mme; put_here: