diff options
Diffstat (limited to 'strings')
-rw-r--r-- | strings/apr_cpystrn.c | 16 | ||||
-rw-r--r-- | strings/apr_strings.c | 3 |
2 files changed, 10 insertions, 9 deletions
diff --git a/strings/apr_cpystrn.c b/strings/apr_cpystrn.c index 6311c29f3bf9..d222d0814299 100644 --- a/strings/apr_cpystrn.c +++ b/strings/apr_cpystrn.c @@ -38,6 +38,7 @@ * (3) Instead of returning the pointer to the beginning of * the destination string, we return a pointer to the * terminating '\0' to allow us to "check" for truncation + * (4) If src is NULL, null terminate dst (empty string copy) * * apr_cpystrn() follows the same call structure as strncpy(). */ @@ -45,19 +46,20 @@ APR_DECLARE(char *) apr_cpystrn(char *dst, const char *src, apr_size_t dst_size) { - char *d, *end; + char *d = dst, *end; if (dst_size == 0) { return (dst); } - d = dst; - end = dst + dst_size - 1; + if (src) { + end = dst + dst_size - 1; - for (; d < end; ++d, ++src) { - if (!(*d = *src)) { - return (d); - } + for (; d < end; ++d, ++src) { + if (!(*d = *src)) { + return (d); + } + } } *d = '\0'; /* always null terminate */ diff --git a/strings/apr_strings.c b/strings/apr_strings.c index d20004eadae4..0ba49c844c67 100644 --- a/strings/apr_strings.c +++ b/strings/apr_strings.c @@ -75,8 +75,7 @@ APR_DECLARE(char *) apr_pstrdup(apr_pool_t *a, const char *s) return NULL; } len = strlen(s) + 1; - res = apr_palloc(a, len); - memcpy(res, s, len); + res = apr_pmemdup(a, s, len); return res; } |