diff options
author | Szabolcs Nagy <nsz@port70.net> | 2015-12-05 21:53:59 +0100 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2015-12-08 18:53:18 -0500 |
commit | 3abb094d19ca4c7c4adcf373d971fb5aa05c5252 (patch) | |
tree | fc33244b55f1d6e788e9129c7a1fe74d0ceaf367 /src/search/tsearch_avl.c | |
parent | 8994908b199a57097f420707b1fca75fc30236fa (diff) | |
download | musl-3abb094d19ca4c7c4adcf373d971fb5aa05c5252.tar.gz musl-3abb094d19ca4c7c4adcf373d971fb5aa05c5252.tar.bz2 musl-3abb094d19ca4c7c4adcf373d971fb5aa05c5252.tar.xz musl-3abb094d19ca4c7c4adcf373d971fb5aa05c5252.zip |
fix tsearch, tfind, tdelete to handle null pointer input
POSIX specifies the behaviour for null rootp input, but it
was not implemented correctly.
Diffstat (limited to 'src/search/tsearch_avl.c')
-rw-r--r-- | src/search/tsearch_avl.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/search/tsearch_avl.c b/src/search/tsearch_avl.c index e4fb1316..57194c84 100644 --- a/src/search/tsearch_avl.c +++ b/src/search/tsearch_avl.c @@ -151,6 +151,8 @@ static struct node *remove(struct node **n, const void *k, void *tdelete(const void *restrict key, void **restrict rootp, int(*compar)(const void *, const void *)) { + if (!rootp) + return 0; struct node *n = *rootp; struct node *ret; /* last argument is arbitrary non-null pointer @@ -163,6 +165,8 @@ void *tdelete(const void *restrict key, void **restrict rootp, void *tfind(const void *key, void *const *rootp, int(*compar)(const void *, const void *)) { + if (!rootp) + return 0; return find(*rootp, key, compar); } @@ -171,6 +175,8 @@ void *tsearch(const void *key, void **rootp, { struct node *update; struct node *ret; + if (!rootp) + return 0; update = insert(*rootp, key, compar, &ret); if (update) *rootp = update; |