Browse Source

When tdelete() is used to delete the root node, don't return a

pointer to the freed root node, but return a pointer to the new
root node. POSIX does not define, what should be returned in
that case.
Fixes Coverity CID 2528.
ok millert@ otto@
OPENBSD_4_0
moritz 18 years ago
parent
commit
699dc2618d
2 changed files with 5 additions and 3 deletions
  1. +2
    -2
      src/lib/libc/stdlib/tsearch.3
  2. +3
    -1
      src/lib/libc/stdlib/tsearch.c

+ 2
- 2
src/lib/libc/stdlib/tsearch.3 View File

@ -1,4 +1,4 @@
.\" $OpenBSD: tsearch.3,v 1.13 2006/01/30 19:50:41 jmc Exp $
.\" $OpenBSD: tsearch.3,v 1.14 2006/04/04 11:21:50 moritz Exp $
.\" .\"
.\" Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com> .\" Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
.\" .\"
@ -74,7 +74,7 @@ and
.Fn tsearch . .Fn tsearch .
If the node to be deleted is the root of the binary search tree, If the node to be deleted is the root of the binary search tree,
.Fa rootp .Fa rootp
will be adjusted.
will be adjusted and a pointer to the new root will be returned.
.Pp .Pp
.Fn twalk .Fn twalk
walks the binary search tree rooted in walks the binary search tree rooted in


+ 3
- 1
src/lib/libc/stdlib/tsearch.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: tsearch.c,v 1.5 2005/03/30 18:51:49 pat Exp $ */
/* $OpenBSD: tsearch.c,v 1.6 2006/04/04 11:21:50 moritz Exp $ */
/* /*
* Tree search generalized from Knuth (6.2.2) Algorithm T just like * Tree search generalized from Knuth (6.2.2) Algorithm T just like
@ -86,6 +86,8 @@ tdelete(const void *vkey, void **vrootp,
q->right = (*rootp)->right; q->right = (*rootp)->right;
} }
} }
if (p == *rootp)
p = q;
free((struct node_t *) *rootp); /* D4: Free node */ free((struct node_t *) *rootp); /* D4: Free node */
*rootp = q; /* link parent to new node */ *rootp = q; /* link parent to new node */
return(p); return(p);


Loading…
Cancel
Save