Author: faridz
Date: Sun Aug 12 18:20:08 2007
New Revision: 565217
URL: http://svn.apache.org/viewvc?view=rev&rev=565217
Log:
2007-08-13 Farid Zaripov <[EMAIL PROTECTED]>
* 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=565217&r1=565216&r2=565217
==============================================================================
--- incubator/stdcxx/trunk/tests/src/char.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/char.cpp Sun Aug 12 18:20:08 2007
@@ -509,7 +509,6 @@
if (src) {
// copy src into dst
memcpy (dst, src, len);
- dst [len] = '\0';
}
else {
// set dst to all NUL
@@ -856,11 +855,13 @@
// if len is non-zero dst must be non-0 as well
RW_ASSERT (0 == len || 0 != dst);
- if (dst) {
+ if (len) {
+ RW_ASSERT (0 != dst);
+
if (src) {
// widen src into dst one element at a time
for (size_t i = 0; ; ++i) {
- if (i == len) {
+ if (i == len - 1) {
dst [i] = L'\0';
break;
}
@@ -873,6 +874,8 @@
memset (dst, 0, len * sizeof *dst);
}
}
+ else if (dst)
+ *dst = L'\0';
return dst;
}
@@ -1004,11 +1007,13 @@
// if len is non-zero dst must be non-0 as well
RW_ASSERT (0 == len || 0 != dst);
- if (dst) {
+ if (len) {
+ RW_ASSERT (0 != dst);
+
if (src) {
// widen src into dst one element at a time
for (size_t i = 0; ; ++i) {
- if (i == len) {
+ if (i == len - 1) {
dst [i] = UserChar::eos ();
break;
}
@@ -1022,6 +1027,8 @@
memset (dst, 0, len * sizeof *dst);
}
}
+ else if (dst)
+ *dst = UserChar::eos ();
return dst;
}