File glibc-2.10-unsetenv.diff of Package glibc

2008-12-01  Ulrich Drepper  <drepper@redhat.com>

	* stdlib/setenv.c (unsetenv): Don't search environment if it does
	not exist.
	* stdlib/Makefile (tests): Add tst-unsetenv1.
	* stdlib/tst-unsetenv1.c: New file.

--- stdlib/Makefile	8 Mar 2008 21:31:19 -0000	1.122
+++ stdlib/Makefile	2 Dec 2008 02:27:21 -0000	1.123
@@ -69,7 +69,7 @@ tests		:= tst-strtol tst-strtod testmb t
 		   test-a64l tst-qsort tst-system testmb2 bug-strtod2	    \
 		   tst-atof1 tst-atof2 tst-strtod2 tst-strtod3 tst-rand48-2 \
 		   tst-makecontext tst-strtod4 tst-strtod5 tst-qsort2	    \
-		   tst-makecontext2 tst-strtod6
+		   tst-makecontext2 tst-strtod6 tst-unsetenv1
 
 include ../Makeconfig
 
--- stdlib/setenv.c	14 Dec 2005 10:44:05 -0000	1.1
+++ stdlib/setenv.c	2 Dec 2008 01:39:44 -0000	1.2
@@ -292,19 +292,20 @@ unsetenv (name)
   LOCK;
 
   ep = __environ;
-  while (*ep != NULL)
-    if (!strncmp (*ep, name, len) && (*ep)[len] == '=')
-      {
-	/* Found it.  Remove this pointer by moving later ones back.  */
-	char **dp = ep;
-
-	do
-	  dp[0] = dp[1];
-	while (*dp++);
-	/* Continue the loop in case NAME appears again.  */
-      }
-    else
-      ++ep;
+  if (ep != NULL)
+    while (*ep != NULL)
+      if (!strncmp (*ep, name, len) && (*ep)[len] == '=')
+	{
+	  /* Found it.  Remove this pointer by moving later ones back.  */
+	  char **dp = ep;
+
+	  do
+	    dp[0] = dp[1];
+	  while (*dp++);
+	  /* Continue the loop in case NAME appears again.  */
+	}
+      else
+	++ep;
 
   UNLOCK;
 
--- stdlib/tst-unsetenv1.c	1 Jan 1970 00:00:00 -0000
+++ stdlib/tst-unsetenv1.c	2 Dec 2008 02:27:12 -0000	1.1
@@ -0,0 +1,12 @@
+#include <stdlib.h>
+
+static int
+do_test (void)
+{
+  clearenv ();
+  unsetenv ("FOO");
+  return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
openSUSE Build Service is sponsored by