stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r387377 - in /incubator/stdcxx/trunk/tests: include/rw_char.h src/char.cpp
Date Tue, 21 Mar 2006 01:43:15 GMT
Author: sebor
Date: Mon Mar 20 17:43:13 2006
New Revision: 387377

URL: http://svn.apache.org/viewcvs?rev=387377&view=rev
Log:
2006-03-20  Martin Sebor  <sebor@roguewave.com>

	* char.cpp (rw_widen): Zeroed out the destination array when the
	source pointer is null and length is less than SIZE_MAX (i.e.,
	implemented the equivalent of memset(dst, 0, len * sizeof *dst)).
	* rw_char.h (rw_widen): Updated comments to reflect the above.

Modified:
    incubator/stdcxx/trunk/tests/include/rw_char.h
    incubator/stdcxx/trunk/tests/src/char.cpp

Modified: incubator/stdcxx/trunk/tests/include/rw_char.h
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/include/rw_char.h?rev=387377&r1=387376&r2=387377&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/include/rw_char.h (original)
+++ incubator/stdcxx/trunk/tests/include/rw_char.h Mon Mar 20 17:43:13 2006
@@ -265,6 +265,9 @@
 // value of str [len]
 // when (len == SIZE_MAX && src != 0), computes len as if by evaluating
 // len = strlen(src)
+// when (src == 0 && len < SIZE_MAX), initializes the first len elements
+// of dst to NUL (i.e., such a call is the equivalent of calling
+// memset(dst, 0, len * sizeof *dst))
 // returns dst
 _TEST_EXPORT
 char* rw_widen (char*         /* dst */,

Modified: incubator/stdcxx/trunk/tests/src/char.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/src/char.cpp?rev=387377&r1=387376&r2=387377&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/src/char.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/char.cpp Mon Mar 20 17:43:13 2006
@@ -231,19 +231,21 @@
 char*
 rw_widen (char *dst, const char *src, size_t len)
 {
-    // allow src to be null
-    if (0 == src)
-        src = "";
-
     // compute the length of src if not specified
     if (_RWSTD_SIZE_MAX == len)
         len = src ? strlen (src) + 1 : 0;
 
-    // copy src into dst
     if (len) {
         RW_ASSERT (0 != dst);
 
-        memcpy (dst, src, len);
+        if (src) {
+            // copy src into dst
+            memcpy (dst, src, len);
+        }
+        else {
+            // set dst to all NUL
+            memset (dst, 0, len);
+        }
     }
     else if (dst)
         *dst = '\0';
@@ -258,10 +260,6 @@
 wchar_t*
 rw_widen (wchar_t *dst, const char *src, size_t len)
 {
-    // allow src to be null
-    if (0 == src)
-        src = "";
-
     // compute the length of src if not specified
     if (_RWSTD_SIZE_MAX == len)
         len = src ? strlen (src) + 1 : 0;
@@ -270,16 +268,22 @@
     RW_ASSERT (0 == len || 0 != dst);
 
     if (dst) {
-        // widen src into dst one element at a time
-        for (size_t i = 0; ; ++i) {
-            typedef unsigned char UChar;
-
-            if (i == len) {
-                dst [i] = L'\0';
-                break;
-            }
+        if (src) {
+            // widen src into dst one element at a time
+            for (size_t i = 0; ; ++i) {
+                typedef unsigned char UChar;
+
+                if (i == len) {
+                    dst [i] = L'\0';
+                    break;
+                }
 
-            dst [i] = wchar_t (UChar (src [i]));
+                dst [i] = wchar_t (UChar (src [i]));
+            }
+        }
+        else {
+            // set dst to all NUL
+            memset (dst, 0, len * sizeof *dst);
         }
     }
 
@@ -293,13 +297,6 @@
 UserChar*
 rw_widen (UserChar *dst, const char *src, size_t len)
 {
-    // dst must point to an array of at least 1 element
-    RW_ASSERT (0 != dst);
-
-    // allow src to be null
-    if (0 == src)
-        src = "";
-
     // compute the length of src if not specified
     if (_RWSTD_SIZE_MAX == len)
         len = src ? strlen (src) + 1 : 0;
@@ -308,17 +305,23 @@
     RW_ASSERT (0 == len || 0 != dst);
 
     if (dst) {
-        // widen src into dst one element at a time
-        for (size_t i = 0; ; ++i) {
-            typedef unsigned char UChar;
-
-            if (i == len) {
-                dst [i] = UserChar::eos ();
-                break;
-            }
+        if (src) {
+            // widen src into dst one element at a time
+            for (size_t i = 0; ; ++i) {
+                typedef unsigned char UChar;
+
+                if (i == len) {
+                    dst [i] = UserChar::eos ();
+                    break;
+                }
 
-            dst [i].f = 0;
-            dst [i].c = UChar (src [i]);
+                dst [i].f = 0;
+                dst [i].c = UChar (src [i]);
+            }
+        }
+        else {
+            // set dst to all NUL
+            memset (dst, 0, len * sizeof *dst);
         }
     }
 



Mime
View raw message