summaryrefslogtreecommitdiff
path: root/src/mesa/main/imports.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/main/imports.c')
-rw-r--r--src/mesa/main/imports.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c
index 890d1a4e32..e2d44fa07c 100644
--- a/src/mesa/main/imports.c
+++ b/src/mesa/main/imports.c
@@ -849,15 +849,23 @@ _mesa_strncmp( const char *s1, const char *s2, size_t n )
return strncmp(s1, s2, n);
}
-/** 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 atoi() */