about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2013-08-02 21:13:16 -0400
committerRich Felker <dalias@aerifal.cx>2013-08-02 21:13:16 -0400
commit2d2da648f6aa07cfca3d6065d9126897e42927a1 (patch)
tree321cd172303af05c61da33659231a5b7750dc982 /src
parent86cc54b577f445da1582d2cf1ac3eff064ca27ef (diff)
downloadmusl-2d2da648f6aa07cfca3d6065d9126897e42927a1.tar.gz
musl-2d2da648f6aa07cfca3d6065d9126897e42927a1.tar.xz
musl-2d2da648f6aa07cfca3d6065d9126897e42927a1.zip
fix aliasing violations in tsearch functions
patch by nsz. the actual object the caller has storing the tree root
has type void *, so accessing it as struct node * is not valid.
instead, simply access the value, move it to a temporary of the
appropriate type and work from there, then move the result back.
Diffstat (limited to 'src')
-rw-r--r--src/search/tsearch_avl.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/search/tsearch_avl.c b/src/search/tsearch_avl.c
index b56159b9..86200928 100644
--- a/src/search/tsearch_avl.c
+++ b/src/search/tsearch_avl.c
@@ -138,9 +138,13 @@ 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 *))
 {
+	struct node *n = *rootp;
+	struct node *ret;
 	/* last argument is arbitrary non-null pointer
 	   which is returned when the root node is deleted */
-	return remove((void*)rootp, key, compar, *rootp);
+	ret = remove(&n, key, compar, n);
+	*rootp = n;
+	return ret;
 }
 
 void *tfind(const void *key, void *const *rootp,
@@ -153,7 +157,11 @@ void *tsearch(const void *key, void **rootp,
 	int (*compar)(const void *, const void *))
 {
 	int new = 0;
-	return insert((void*)rootp, key, compar, &new);
+	struct node *n = *rootp;
+	struct node *ret;
+	ret = insert(&n, key, compar, &new);
+	*rootp = n;
+	return ret;
 }
 
 static void walk(const struct node *r, void (*action)(const void *, VISIT, int), int d)