summaryrefslogtreecommitdiff
path: root/nsprpub/lib/libc/src/strdup.c
diff options
context:
space:
mode:
Diffstat (limited to 'nsprpub/lib/libc/src/strdup.c')
-rw-r--r--nsprpub/lib/libc/src/strdup.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/nsprpub/lib/libc/src/strdup.c b/nsprpub/lib/libc/src/strdup.c
index c267147ce9..d2deae43c4 100644
--- a/nsprpub/lib/libc/src/strdup.c
+++ b/nsprpub/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';