Index: contrib/mtree/spec.c =================================================================== --- contrib/mtree/spec.c +++ contrib/mtree/spec.c @@ -100,7 +100,7 @@ static void replacenode(NODE *, NODE *); static void set(char *, NODE *); static void unset(char *, NODE *); -static void addchild(NODE *, NODE *); +static void addchild(NODE *, NODE **); static int nodecmp(const NODE *, const NODE *); static int appendfield(FILE *, int, const char *, ...) __printflike(3, 4); @@ -235,7 +235,7 @@ * full path entry; add or replace */ centry->parent = pathparent; - addchild(pathparent, centry); + addchild(pathparent, ¢ry); last = centry; } else if (strcmp(centry->name, ".") == 0) { /* @@ -248,7 +248,7 @@ * add or replace */ centry->parent = last; - addchild(last, centry); + addchild(last, ¢ry); last = centry; } else { /* @@ -257,7 +257,7 @@ * add or replace */ centry->parent = last->parent; - addchild(last->parent, centry); + addchild(last->parent, ¢ry); last = centry; } } @@ -717,8 +717,9 @@ * pathparent->child. Keep the list sorted if Sflag is set. */ static void -addchild(NODE *pathparent, NODE *centry) +addchild(NODE *pathparent, NODE **pcentry) { + NODE *centry = *pcentry; NODE *samename; /* node with the same name as centry */ NODE *replacepos; /* if non-NULL, centry should replace this node */ NODE *insertpos; /* if non-NULL, centry should be inserted @@ -778,6 +779,8 @@ * free the information in the centry node. */ replacenode(samename, centry); + *pcentry = samename; + centry = *pcentry; if (samename == replacepos) { /* The just-replaced node was in the correct position */ return; @@ -800,7 +803,6 @@ * the just-replaced node from the list, and allow it to * be insterted in the correct position later. */ - centry = samename; if (centry->prev) centry->prev->next = centry->next; else {