mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] fix tsearch, tfind, tdelete to handle null pointer input
@ 2015-12-05 20:53 Szabolcs Nagy
  0 siblings, 0 replies; only message in thread
From: Szabolcs Nagy @ 2015-12-05 20:53 UTC (permalink / raw)
  To: musl; +Cc: Ed Schouten

POSIX specifies the behaviour for null rootp input, but it
was not implemented correctly.
---
 src/search/tsearch_avl.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/search/tsearch_avl.c b/src/search/tsearch_avl.c
index e4fb131..57194c8 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;
-- 
2.4.1



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-12-05 20:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-05 20:53 [PATCH] fix tsearch, tfind, tdelete to handle null pointer input Szabolcs Nagy

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).