diff options
author | Brian <[email protected]> | 2006-12-14 13:59:53 -0700 |
---|---|---|
committer | Brian <[email protected]> | 2006-12-14 13:59:53 -0700 |
commit | 200736ebd8c82b03b781a6c6481d05deb1f0c8bf (patch) | |
tree | ed1c5c2f916543ae6b476849fcb2000a9ab55ed4 /src/mesa | |
parent | cc0c8b224880c6d6d5bf09f1d37b4275da476afd (diff) |
Modify _mesa_strdup() so it handles NULL correctly.
Diffstat (limited to 'src/mesa')
-rw-r--r-- | src/mesa/main/imports.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c index a09c497795e..9c7ebf9287d 100644 --- a/src/mesa/main/imports.c +++ b/src/mesa/main/imports.c @@ -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() */ |