diff options
author | Eugene Syromiatnikov <evgsyr@gmail.com> | 2017-08-24 17:36:08 +0000 |
---|---|---|
committer | Eugene Syromyatnikov <evgsyr@gmail.com> | 2017-08-24 20:06:54 +0200 |
commit | 7ba0d89c9f9710bb550201436840079fb71b18be (patch) | |
tree | 4d5ecf0035de59decf5cef3e30f547fe75569fd1 /xmalloc.c | |
parent | 2b786e0113c105e2434d4e9069797321628b4ab3 (diff) | |
download | strace-7ba0d89c9f9710bb550201436840079fb71b18be.tar.gz |
xstrdup, xtrndup: allow NULL argument
Accept NULL argument in xstrdup and xtrndup functions to allow use
of "xstrdup(str)" instead of "str ? xstrdup(str) : NULL".
* xmalloc.c (xstrdup, xstrndup): Handle NULL argument.
* xmalloc.h: Add comment regarding this deviation from the behaviour
of the POSIX counterparts of these functions.
Diffstat (limited to 'xmalloc.c')
-rw-r--r-- | xmalloc.c | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -91,6 +91,9 @@ xreallocarray(void *ptr, size_t nmemb, size_t size) char * xstrdup(const char *str) { + if (!str) + return NULL; + char *p = strdup(str); if (!p) @@ -104,6 +107,9 @@ xstrndup(const char *str, size_t n) { char *p; + if (!str) + return NULL; + #ifdef HAVE_STRNDUP p = strndup(str, n); #else |