summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorguenther <>2012-02-06 20:29:54 +0000
committerguenther <>2012-02-06 20:29:54 +0000
commit8a83e74e706942a4d9581f028c6d4ac43c103243 (patch)
tree5b91ee6121e35ca2e7de7a1edefccfd92041c6f0
parent4c9ce2d2836b9397408b8a88299a27eb06f98fda (diff)
downloadopenbsd-8a83e74e706942a4d9581f028c6d4ac43c103243.tar.gz
openbsd-8a83e74e706942a4d9581f028c6d4ac43c103243.tar.bz2
openbsd-8a83e74e706942a4d9581f028c6d4ac43c103243.zip
Revert previous diff as it resulted in the wrong return code when
the last node is deleted. Instead, resolve the Coverity warning by returning (node *)1 when you delete the root node. based an idea from millert@. ok otto@
-rw-r--r--src/lib/libc/stdlib/tsearch.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/lib/libc/stdlib/tsearch.c b/src/lib/libc/stdlib/tsearch.c
index 667c57731b..2f5e369f6a 100644
--- a/src/lib/libc/stdlib/tsearch.c
+++ b/src/lib/libc/stdlib/tsearch.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tsearch.c,v 1.6 2006/04/04 11:21:50 moritz Exp $ */ 1/* $OpenBSD: tsearch.c,v 1.7 2012/02/06 20:29:54 guenther Exp $ */
2 2
3/* 3/*
4 * Tree search generalized from Knuth (6.2.2) Algorithm T just like 4 * Tree search generalized from Knuth (6.2.2) Algorithm T just like
@@ -56,12 +56,12 @@ tdelete(const void *vkey, void **vrootp,
56{ 56{
57 node **rootp = (node **)vrootp; 57 node **rootp = (node **)vrootp;
58 char *key = (char *)vkey; 58 char *key = (char *)vkey;
59 node *p; 59 node *p = (node *)1;
60 node *q; 60 node *q;
61 node *r; 61 node *r;
62 int cmp; 62 int cmp;
63 63
64 if (rootp == (struct node_t **)0 || (p = *rootp) == (struct node_t *)0) 64 if (rootp == (struct node_t **)0 || *rootp == (struct node_t *)0)
65 return ((struct node_t *)0); 65 return ((struct node_t *)0);
66 while ((cmp = (*compar)(key, (*rootp)->key)) != 0) { 66 while ((cmp = (*compar)(key, (*rootp)->key)) != 0) {
67 p = *rootp; 67 p = *rootp;
@@ -86,8 +86,6 @@ tdelete(const void *vkey, void **vrootp,
86 q->right = (*rootp)->right; 86 q->right = (*rootp)->right;
87 } 87 }
88 } 88 }
89 if (p == *rootp)
90 p = q;
91 free((struct node_t *) *rootp); /* D4: Free node */ 89 free((struct node_t *) *rootp); /* D4: Free node */
92 *rootp = q; /* link parent to new node */ 90 *rootp = q; /* link parent to new node */
93 return(p); 91 return(p);