summaryrefslogtreecommitdiff
path: root/lib/libc/src/strdup.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/src/strdup.c')
-rw-r--r--lib/libc/src/strdup.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/libc/src/strdup.c b/lib/libc/src/strdup.c
index c267147c..d2deae43 100644
--- a/lib/libc/src/strdup.c
+++ b/lib/libc/src/strdup.c
@@ -13,13 +13,16 @@ PL_strdup(const char *s)
char *rv;
size_t n;
- if( (const char *)0 == s )
+ if( (const char *)0 == s ) {
s = "";
+ }
n = strlen(s) + 1;
rv = (char *)malloc(n);
- if( (char *)0 == rv ) return rv;
+ if( (char *)0 == rv ) {
+ return rv;
+ }
(void)memcpy(rv, s, n);
@@ -38,13 +41,16 @@ PL_strndup(const char *s, PRUint32 max)
char *rv;
size_t l;
- if( (const char *)0 == s )
+ if( (const char *)0 == s ) {
s = "";
+ }
l = PL_strnlen(s, max);
rv = (char *)malloc(l+1);
- if( (char *)0 == rv ) return rv;
+ if( (char *)0 == rv ) {
+ return rv;
+ }
(void)memcpy(rv, s, l);
rv[l] = '\0';