Index: contrib/mtree/spec.c =================================================================== --- contrib/mtree/spec.c +++ contrib/mtree/spec.c @@ -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 @@ -734,7 +735,7 @@ cur = pathparent->child; if (cur == NULL) { /* centry is pathparent's first and only child node so far */ - pathparent->child = *centry; + pathparent->child = centry; return; } @@ -748,11 +749,11 @@ * (setting replacepos and/or insertpos). */ for (; cur != NULL; last = cur, cur = cur->next) { - if (strcmp((*centry)->name, cur->name) == 0) { + if (strcmp(centry->name, cur->name) == 0) { samename = cur; } if (mtree_Sflag) { - cmp = nodecmp(*centry, cur); + cmp = nodecmp(centry, cur); if (cmp == 0) { replacepos = cur; } else if (cmp > 0) { @@ -777,8 +778,9 @@ * or replace the information in the samename node and * free the information in the centry node. */ - replacenode(samename, *centry); - *centry = samename; + replacenode(samename, centry); + *pcentry = samename; + centry = *pcentry; if (samename == replacepos) { /* The just-replaced node was in the correct position */ return; @@ -801,33 +803,32 @@ * 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; + if (centry->prev) + centry->prev->next = centry->next; else { /* centry->next is the new head of the list */ - pathparent->child = (*centry)->next; - assert((*centry)->next != NULL); + pathparent->child = centry->next; + assert(centry->next != NULL); } - if ((*centry)->next) - (*centry)->next->prev = (*centry)->prev; - (*centry)->prev = NULL; - (*centry)->next = NULL; + if (centry->next) + centry->next->prev = centry->prev; + centry->prev = NULL; + centry->next = NULL; } if (insertpos == NULL) { /* insert centry at the beginning of the list */ - pathparent->child->prev = *centry; - (*centry)->next = pathparent->child; - (*centry)->prev = NULL; - pathparent->child = *centry; + pathparent->child->prev = centry; + centry->next = pathparent->child; + centry->prev = NULL; + pathparent->child = centry; } else { /* insert centry into the list just after insertpos */ - (*centry)->next = insertpos->next; - insertpos->next = *centry; - (*centry)->prev = insertpos; - if ((*centry)->next) - (*centry)->next->prev = *centry; + centry->next = insertpos->next; + insertpos->next = centry; + centry->prev = insertpos; + if (centry->next) + centry->next->prev = centry; } return; }