apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r1533104 - /apr/apr/trunk/strings/apr_cpystrn.c
Date Thu, 17 Oct 2013 15:09:44 GMT
Author: jim
Date: Thu Oct 17 15:09:43 2013
New Revision: 1533104

URL: http://svn.apache.org/r1533104
Log:
it should really handle src==NULL 

Modified:
    apr/apr/trunk/strings/apr_cpystrn.c

Modified: apr/apr/trunk/strings/apr_cpystrn.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/strings/apr_cpystrn.c?rev=1533104&r1=1533103&r2=1533104&view=diff
==============================================================================
--- apr/apr/trunk/strings/apr_cpystrn.c (original)
+++ apr/apr/trunk/strings/apr_cpystrn.c Thu Oct 17 15:09:43 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 */



Mime
View raw message