summaryrefslogtreecommitdiff
path: root/strings
diff options
context:
space:
mode:
authorJim Jagielski <jim@apache.org>2013-10-17 15:10:11 +0000
committerJim Jagielski <jim@apache.org>2013-10-17 15:10:11 +0000
commit83f1d0dd4db126de59e7c23dcfaacfe247743b4a (patch)
treea1e334e9d4bc5b999a88b3f65784de0e19fdfcad /strings
parentfd2c51a0674a0a50a526e98ed651e0c477e9c86c (diff)
downloadapr-83f1d0dd4db126de59e7c23dcfaacfe247743b4a.tar.gz
Merge r1533104 from trunk:
it should really handle src==NULL Reviewed/backported by: jim git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.5.x@1533105 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'strings')
-rw-r--r--strings/apr_cpystrn.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/strings/apr_cpystrn.c b/strings/apr_cpystrn.c
index 6311c29f3..d6c98f7e9 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().
*/
@@ -51,13 +52,15 @@ APR_DECLARE(char *) apr_cpystrn(char *dst, const char *src, apr_size_t dst_size)
return (dst);
}
- d = dst;
- end = dst + dst_size - 1;
+ if (src) {
+ d = dst;
+ 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 */