aboutsummaryrefslogtreecommitdiffstats
path: root/main/musl/0019-fix-tsearch-tfind-tdelete-to-handle-null-pointer-inp.patch
blob: a6ea0ad7537b2b6952cb788ae6c32fd803e614d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
From 3abb094d19ca4c7c4adcf373d971fb5aa05c5252 Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <nsz@port70.net>
Date: Sat, 5 Dec 2015 21:53:59 +0100
Subject: [PATCH] fix tsearch, tfind, tdelete to handle null pointer input

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.7.0