Subject: Re: NetBSD-current distribution build failed - problems in libc
To: None <current-users@netbsd.org>
From: Arne H. Juul <arnej@pvv.ntnu.no>
List: current-users
Date: 03/23/2005 18:44:06
kleink added a const to the argument per SVID, so now lint
complains.  I suggest simplifying, I don't understand why it
needs a pointer-to-pointer at all.  This diff is not well-tested
but compiles and lints and looks much more logical (at least to
me), and should be equivalent to the old code.

Index: stdlib/tfind.c
===================================================================
RCS file: /usr/cvs/src/lib/libc/stdlib/tfind.c,v
retrieving revision 1.4
diff -u -r1.4 tfind.c
--- stdlib/tfind.c	22 Mar 2005 20:13:42 -0000	1.4
+++ stdlib/tfind.c	23 Mar 2005 17:30:23 -0000
@@ -28,22 +28,24 @@
  	void * const *vrootp;		/* address of the tree root */
  	int (*compar) __P((const void *, const void *));
  {
-	node_t **rootp = (node_t **)vrootp;
+	node_t *rootp;

  	_DIAGASSERT(vkey != NULL);
  	_DIAGASSERT(compar != NULL);

-	if (rootp == NULL)
+	if (vrootp == NULL)
  		return NULL;

-	while (*rootp != NULL) {		/* T1: */
+	rootp = *vrootp;
+
+	while (rootp != NULL) {		/* T1: */
  		int r;

-		if ((r = (*compar)(vkey, (*rootp)->key)) == 0)	/* T2: */
-			return *rootp;		/* key found */
+		if ((r = (*compar)(vkey, rootp->key)) == 0)	/* T2: */
+			return rootp;		/* key found */
  		rootp = (r < 0) ?
-		    &(*rootp)->llink :		/* T3: follow left branch */
-		    &(*rootp)->rlink;		/* T4: follow right branch */
+		    rootp->llink :		/* T3: follow left branch */
+		    rootp->rlink;		/* T4: follow right branch */
  	}
  	return NULL;
  }