Modify _mesa_strdup() so it handles NULL correctly.
authorBrian <brian@yutani.localnet.net>
Thu, 14 Dec 2006 20:59:53 +0000 (13:59 -0700)
committerBrian <brian@yutani.localnet.net>
Thu, 14 Dec 2006 20:59:53 +0000 (13:59 -0700)
src/mesa/main/imports.c

index a09c497..9c7ebf9 100644 (file)
@@ -920,15 +920,23 @@ _mesa_strncmp( const char *s1, const char *s2, size_t n )
 #endif
 }
 
-/** Implemented using _mesa_malloc() and _mesa_strcpy */
+/**
+ * Implemented using _mesa_malloc() and _mesa_strcpy.
+ * Note that NULL is handled accordingly.
+ */
 char *
 _mesa_strdup( const char *s )
 {
-   size_t l = _mesa_strlen(s);
-   char *s2 = (char *) _mesa_malloc(l + 1);
-   if (s2)
-      _mesa_strcpy(s2, s);
-   return s2;
+   if (s) {
+      size_t l = _mesa_strlen(s);
+      char *s2 = (char *) _mesa_malloc(l + 1);
+      if (s2)
+         _mesa_strcpy(s2, s);
+      return s2;
+   }
+   else {
+      return NULL;
+   }
 }
 
 /** Wrapper around either atoi() or xf86atoi() */