You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by ji...@apache.org on 2013/10/17 17:15:06 UTC

svn commit: r1533108 - in /apr/apr/branches/1.5.x: ./ strings/apr_cpystrn.c

Author: jim
Date: Thu Oct 17 15:15:06 2013
New Revision: 1533108

URL: http://svn.apache.org/r1533108
Log:
Merge r1533104 from trunk:

it should really handle src==NULL 

Reviewed/backported by: jim

Modified:
    apr/apr/branches/1.5.x/   (props changed)
    apr/apr/branches/1.5.x/strings/apr_cpystrn.c

Propchange: apr/apr/branches/1.5.x/
------------------------------------------------------------------------------
  Merged /apr/apr/trunk:r1533104

Modified: apr/apr/branches/1.5.x/strings/apr_cpystrn.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/strings/apr_cpystrn.c?rev=1533108&r1=1533107&r2=1533108&view=diff
==============================================================================
--- apr/apr/branches/1.5.x/strings/apr_cpystrn.c (original)
+++ apr/apr/branches/1.5.x/strings/apr_cpystrn.c Thu Oct 17 15:15:06 2013
@@ -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 *ds
         return (dst);
     }
 
-    d = dst;
-    end = dst + dst_size - 1;
-
-    for (; d < end; ++d, ++src) {
-	if (!(*d = *src)) {
-	    return (d);
-	}
+    if (src) {
+        d = dst;
+        end = dst + dst_size - 1;
+
+        for (; d < end; ++d, ++src) {
+            if (!(*d = *src)) {
+                return (d);
+            }
+        }
     }
 
     *d = '\0';	/* always null terminate */