diff options
author | peter <peter@FreeBSD.org> | 2014-05-27 07:15:14 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 2014-05-27 07:15:14 +0000 |
commit | 073d039ce1755179ade6d76571f16045ade34213 (patch) | |
tree | 0e023fb89b7a7e9a4fa11cfb7d9118a7510d2640 /contrib/apr/strings/apr_cpystrn.c | |
parent | c5be37fb1f34d0c40f8f70140824b785f414c4da (diff) | |
parent | ca02a2bfd2f08739388e00fb3bbe93fa3fa5efb0 (diff) | |
download | FreeBSD-src-073d039ce1755179ade6d76571f16045ade34213.zip FreeBSD-src-073d039ce1755179ade6d76571f16045ade34213.tar.gz |
Merge apr-1.4.8 -> apr-1.5.1 and update.
Diffstat (limited to 'contrib/apr/strings/apr_cpystrn.c')
-rw-r--r-- | contrib/apr/strings/apr_cpystrn.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/contrib/apr/strings/apr_cpystrn.c b/contrib/apr/strings/apr_cpystrn.c index 6311c29..d222d08 100644 --- a/contrib/apr/strings/apr_cpystrn.c +++ b/contrib/apr/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 */ |