Windows: Don't attempt to copy a string to a zero length buffer
authorAsanka Herath <asanka@secure-endpoints.com>
Tue, 24 Aug 2010 04:04:51 +0000 (00:04 -0400)
committerAsanka C. Herath <asanka@secure-endpoints.com>
Tue, 14 Sep 2010 12:03:33 +0000 (08:03 -0400)
It won't cause harm since strcpy_s() deals with zero length buffers,
but it invokes the invalid parameter handler, which can disrupt
execution on debug builds.

lib/roken/strlcpy.c

index 7c1789bd1f95b15053c5a16c1e0d9ba177cb24e9..0fe2b97fccb22e0dc83770ac08f6a0849fb5afae 100644 (file)
@@ -43,7 +43,8 @@ strlcpy (char *dst, const char *src, size_t dst_cch)
 {
     errno_t e;
 
-    e = strcpy_s(dst, dst_cch, src);
+    if (dst_cch > 0)
+        e = strncpy_s(dst, dst_cch, src, _TRUNCATE);
 
     return strlen (src);
 }