stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From far...@apache.org
Subject svn commit: r565221 - /incubator/stdcxx/trunk/tests/src/char.cpp
Date Mon, 13 Aug 2007 01:47:18 GMT
Author: faridz
Date: Sun Aug 12 18:47:17 2007
New Revision: 565221

URL: http://svn.apache.org/viewvc?view=rev&rev=565221
Log:
2007-08-13 Farid Zaripov <Farid_Zaripov@epam.com>

	* char.cpp (rw_widen): Don't write after end of dst.

Modified:
    incubator/stdcxx/trunk/tests/src/char.cpp

Modified: incubator/stdcxx/trunk/tests/src/char.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/src/char.cpp?view=diff&rev=565221&r1=565220&r2=565221
==============================================================================
--- incubator/stdcxx/trunk/tests/src/char.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/char.cpp Sun Aug 12 18:47:17 2007
@@ -501,7 +501,7 @@
 {
     // compute the length of src if not specified
     if (_RWSTD_SIZE_MAX == len)
-        len = src ? strlen (src) + 1 : 0;
+        len = src ? strlen (src) : 0;
 
     if (len) {
         RW_ASSERT (0 != dst);
@@ -509,6 +509,7 @@
         if (src) {
             // copy src into dst
             memcpy (dst, src, len);
+            dst [len] = '\0';
         }
         else {
             // set dst to all NUL
@@ -850,18 +851,16 @@
 {
     // compute the length of src if not specified
     if (_RWSTD_SIZE_MAX == len)
-        len = src ? strlen (src) + 1 : 0;
+        len = src ? strlen (src) : 0;
 
     // if len is non-zero dst must be non-0 as well
     RW_ASSERT (0 == len || 0 != dst);
 
-    if (len) {
-        RW_ASSERT (0 != dst);
-
+    if (dst) {
         if (src) {
             // widen src into dst one element at a time
             for (size_t i = 0; ; ++i) {
-                if (i == len - 1) {
+                if (i == len) {
                     dst [i] = L'\0';
                     break;
                 }
@@ -874,8 +873,6 @@
             memset (dst, 0, len * sizeof *dst);
         }
     }
-    else if (dst)
-        *dst = L'\0';
 
     return dst;
 }
@@ -1002,18 +999,16 @@
 {
     // compute the length of src if not specified
     if (_RWSTD_SIZE_MAX == len)
-        len = src ? strlen (src) + 1 : 0;
+        len = src ? strlen (src) : 0;
 
     // if len is non-zero dst must be non-0 as well
     RW_ASSERT (0 == len || 0 != dst);
 
-    if (len) {
-        RW_ASSERT (0 != dst);
-
+    if (dst) {
         if (src) {
             // widen src into dst one element at a time
             for (size_t i = 0; ; ++i) {
-                if (i == len - 1) {
+                if (i == len) {
                     dst [i] = UserChar::eos ();
                     break;
                 }
@@ -1027,8 +1022,6 @@
             memset (dst, 0, len * sizeof *dst);
         }
     }
-    else if (dst)
-        *dst = UserChar::eos ();
 
     return dst;
 }



Mime
View raw message