diff options
author | 2012-02-06 20:29:54 +0000 | |
---|---|---|
committer | 2012-02-06 20:29:54 +0000 | |
commit | d8bc65b25aa974fd8343e701b6a835a6d6a333c1 (patch) | |
tree | b2f2b6dfbe567896ca1445615e78d7ef5175b2bb /lib/libc/stdlib/tsearch.c | |
parent | Don't die if fail to get root directory, from Ben Boeckel. (diff) | |
download | wireguard-openbsd-d8bc65b25aa974fd8343e701b6a835a6d6a333c1.tar.xz wireguard-openbsd-d8bc65b25aa974fd8343e701b6a835a6d6a333c1.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@
Diffstat (limited to 'lib/libc/stdlib/tsearch.c')
-rw-r--r-- | lib/libc/stdlib/tsearch.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/lib/libc/stdlib/tsearch.c b/lib/libc/stdlib/tsearch.c index 667c57731bb..2f5e369f6ad 100644 --- a/lib/libc/stdlib/tsearch.c +++ b/lib/libc/stdlib/tsearch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tsearch.c,v 1.6 2006/04/04 11:21:50 moritz Exp $ */ +/* $OpenBSD: tsearch.c,v 1.7 2012/02/06 20:29:54 guenther Exp $ */ /* * Tree search generalized from Knuth (6.2.2) Algorithm T just like @@ -56,12 +56,12 @@ tdelete(const void *vkey, void **vrootp, { node **rootp = (node **)vrootp; char *key = (char *)vkey; - node *p; + node *p = (node *)1; node *q; node *r; int cmp; - if (rootp == (struct node_t **)0 || (p = *rootp) == (struct node_t *)0) + if (rootp == (struct node_t **)0 || *rootp == (struct node_t *)0) return ((struct node_t *)0); while ((cmp = (*compar)(key, (*rootp)->key)) != 0) { p = *rootp; @@ -86,8 +86,6 @@ tdelete(const void *vkey, void **vrootp, q->right = (*rootp)->right; } } - if (p == *rootp) - p = q; free((struct node_t *) *rootp); /* D4: Free node */ *rootp = q; /* link parent to new node */ return(p); |