Attached is a patch for resolve issue STDCXX-93.
ChangeLog:
STDCXX-93
* time_put.cpp (__rw_get_timepunct): Corrected buffer size in
wcsftime() calls; _RWSTD_SIZE_MAX changed to size of source
string in mbstowcs() calls to deal with MSVC 8.0 CRT
Farid.
Index: time_put.cpp
===================================================================
--- time_put.cpp (revision 453153)
+++ time_put.cpp (working copy)
@@ -707,13 +707,13 @@
# ifndef _RWSTD_NO_WCSFTIME
wchar_t *pwbuf = _RWSTD_REINTERPRET_CAST (wchar_t*, pbuf + off);
- len = wcsftime (pwbuf, bufsize - off, L"%a", &t);
+ len = wcsftime (pwbuf, (bufsize - off) / sizeof (*pwbuf), L"%a", &t);
pun->abday_off [1][t.tm_wday] = off;
off += (len + 1) * sizeof (wchar_t);
pwbuf = _RWSTD_REINTERPRET_CAST (wchar_t*, pbuf + off);
- len = wcsftime (pwbuf, bufsize - off, L"%A", &t);
+ len = wcsftime (pwbuf, (bufsize - off) / sizeof (*pwbuf), L"%A", &t);
pun->day_off [1][t.tm_wday] = off;
off += (len + 1) * sizeof (wchar_t);
@@ -725,8 +725,12 @@
const char *str =
_RWSTD_STATIC_CAST (const char*, pun->abday (t.tm_wday, 0));
+ _RWSTD_ASSERT (0 != str);
+
+ _RWSTD_SIZE_T size = 1 + strlen (str);
+
wchar_t *pwbuf = _RWSTD_REINTERPRET_CAST (wchar_t*, pbuf + off);
- _RWSTD_SIZE_T size = mbstowcs (pwbuf, str, _RWSTD_SIZE_MAX);
+ size = mbstowcs (pwbuf, str, size);
if (_RWSTD_SIZE_MAX == size) {
// conversion failure - should not happen
@@ -741,9 +745,14 @@
pun->abday_off [1][t.tm_wday] = off;
off += size * sizeof (wchar_t);
- str = _RWSTD_STATIC_CAST (const char*, pun->day (t.tm_wday, 0));
+ str = _RWSTD_STATIC_CAST (const char*, pun->day (t.tm_wday, 0));
+
+ _RWSTD_ASSERT (0 != str);
+
+ size = 1 + strlen (str);
+
pwbuf = _RWSTD_REINTERPRET_CAST (wchar_t*, pbuf + off);
- size = mbstowcs (pwbuf, str, _RWSTD_SIZE_MAX);
+ size = mbstowcs (pwbuf, str, size);
if (_RWSTD_SIZE_MAX == size) {
// conversion failure - should not happen
@@ -786,13 +795,13 @@
# ifndef _RWSTD_NO_WCSFTIME
wchar_t *pwbuf = _RWSTD_REINTERPRET_CAST (wchar_t*, pbuf + off);
- len = wcsftime (pwbuf, bufsize - off, L"%b", &t);
+ len = wcsftime (pwbuf, (bufsize - off) / sizeof (*pwbuf), L"%b", &t);
pun->abmon_off [1][t.tm_mon] = off;
off += (len + 1) * sizeof (wchar_t);
pwbuf = _RWSTD_REINTERPRET_CAST (wchar_t*, pbuf + off);
- len = wcsftime (pwbuf, bufsize - off, L"%B", &t);
+ len = wcsftime (pwbuf, (bufsize - off) / sizeof (*pwbuf), L"%B", &t);
pun->mon_off [1][t.tm_mon] = off;
off += (len + 1) * sizeof (wchar_t);
@@ -804,8 +813,12 @@
const char *str =
_RWSTD_STATIC_CAST (const char*, pun->abmon (t.tm_mon, 0));
+ _RWSTD_ASSERT (0 != str);
+
+ _RWSTD_SIZE_T size = 1 + strlen (str);
+
wchar_t *pwbuf = _RWSTD_REINTERPRET_CAST (wchar_t*, pbuf + off);
- _RWSTD_SIZE_T size = mbstowcs (pwbuf, str, _RWSTD_SIZE_MAX);
+ size = mbstowcs (pwbuf, str, size);
if (_RWSTD_SIZE_MAX == size) {
// conversion failure - should not happen
@@ -820,9 +833,14 @@
pun->abmon_off [1][t.tm_mon] = off;
off += size * sizeof (wchar_t);
- str = _RWSTD_STATIC_CAST (const char*, pun->mon (t.tm_mon, 0));
+ str = _RWSTD_STATIC_CAST (const char*, pun->mon (t.tm_mon, 0));
+
+ _RWSTD_ASSERT (0 != str);
+
+ size = 1 + strlen (str);
+
pwbuf = _RWSTD_REINTERPRET_CAST (wchar_t*, pbuf + off);
- size = mbstowcs (pwbuf, str, _RWSTD_SIZE_MAX);
+ size = mbstowcs (pwbuf, str, size);
if (_RWSTD_SIZE_MAX == size) {
// conversion failure - should not happen
@@ -905,21 +923,26 @@
t.tm_hour = 1;
pwbuf = _RWSTD_REINTERPRET_CAST (wchar_t*, pbuf + off);
- len = wcsftime (pwbuf, bufsize - off, L"%p", &t);
+ len = wcsftime (pwbuf, (bufsize - off) / sizeof (*pwbuf), L"%p", &t);
pun->am_pm_off [1][0] = off;
off += (len + 1) * sizeof (wchar_t);
t.tm_hour = 13;
pwbuf = _RWSTD_REINTERPRET_CAST (wchar_t*, pbuf + off);
- len = wcsftime (pwbuf, bufsize - off, L"%p", &t);
+ len = wcsftime (pwbuf, (bufsize - off) / sizeof (*pwbuf), L"%p", &t);
pun->am_pm_off [1][1] = off;
off += (len + 1) * sizeof (wchar_t);
# else // if defined (_RWSTD_NO_WCSFTIME)
- str = _RWSTD_STATIC_CAST (const char*, pun->am_pm (0, 0));
+ str = _RWSTD_STATIC_CAST (const char*, pun->am_pm (0, 0));
+
+ _RWSTD_ASSERT (0 != str);
+
+ size = 1 + strlen (str);
+
pwbuf = _RWSTD_REINTERPRET_CAST (wchar_t*, pbuf + off);
- size = mbstowcs (pwbuf, str, _RWSTD_SIZE_MAX);
+ size = mbstowcs (pwbuf, str, size);
if (_RWSTD_SIZE_MAX == size) {
// conversion failure - should not happen
@@ -934,9 +957,14 @@
pun->am_pm_off [1][0] = off;
off += size * sizeof (wchar_t);
- str = _RWSTD_STATIC_CAST (const char*, pun->am_pm (1, 0));
+ str = _RWSTD_STATIC_CAST (const char*, pun->am_pm (1, 0));
+
+ _RWSTD_ASSERT (0 != str);
+
+ size = 1 + strlen (str);
+
pwbuf = _RWSTD_REINTERPRET_CAST (wchar_t*, pbuf + off);
- size = mbstowcs (pwbuf, str, _RWSTD_SIZE_MAX);
+ size = mbstowcs (pwbuf, str, size);
if (_RWSTD_SIZE_MAX == size) {
// conversion failure - should not happen
@@ -954,9 +982,14 @@
# endif // _RWSTD_NO_WCSFTIME
// convert "%x" to its wide equivalent
- str = _RWSTD_STATIC_CAST (const char*, pun->d_fmt (0));
+ str = _RWSTD_STATIC_CAST (const char*, pun->d_fmt (0));
+
+ _RWSTD_ASSERT (0 != str);
+
+ size = 1 + strlen (str);
+
pwbuf = _RWSTD_REINTERPRET_CAST (wchar_t*, pbuf + off);
- size = mbstowcs (pwbuf, str, _RWSTD_SIZE_MAX);
+ size = mbstowcs (pwbuf, str, size);
if (_RWSTD_SIZE_MAX == size) {
// conversion failure - should not happen
@@ -972,9 +1005,14 @@
off += size * sizeof (wchar_t);
// convert "%X" to its wide equivalent
- str = _RWSTD_STATIC_CAST (const char*, pun->t_fmt (0));
+ str = _RWSTD_STATIC_CAST (const char*, pun->t_fmt (0));
+
+ _RWSTD_ASSERT (0 != str);
+
+ size = 1 + strlen (str);
+
pwbuf = _RWSTD_REINTERPRET_CAST (wchar_t*, pbuf + off);
- size = mbstowcs (pwbuf, str, _RWSTD_SIZE_MAX);
+ size = mbstowcs (pwbuf, str, size);
if (_RWSTD_SIZE_MAX == size) {
// conversion failure - should not happen
@@ -990,9 +1028,14 @@
off += size * sizeof (wchar_t);
// convert "%c" to its wide equivalent
- str = _RWSTD_STATIC_CAST (const char*, pun->d_t_fmt (0));
+ str = _RWSTD_STATIC_CAST (const char*, pun->d_t_fmt (0));
+
+ _RWSTD_ASSERT (0 != str);
+
+ size = 1 + strlen (str);
+
pwbuf = _RWSTD_REINTERPRET_CAST (wchar_t*, pbuf + off);
- size = mbstowcs (pwbuf, str, _RWSTD_SIZE_MAX);
+ size = mbstowcs (pwbuf, str, size);
if (_RWSTD_SIZE_MAX == size) {
// conversion failure - should not happen
@@ -1008,9 +1051,14 @@
off += size * sizeof (wchar_t);
// convert "%r" to its wide equivalent
- str = _RWSTD_STATIC_CAST (const char*, pun->t_fmt_ampm (0));
+ str = _RWSTD_STATIC_CAST (const char*, pun->t_fmt_ampm (0));
+
+ _RWSTD_ASSERT (0 != str);
+
+ size = 1 + strlen (str);
+
pwbuf = _RWSTD_REINTERPRET_CAST (wchar_t*, pbuf + off);
- size = mbstowcs (pwbuf, str, _RWSTD_SIZE_MAX);
+ size = mbstowcs (pwbuf, str, size);
if (_RWSTD_SIZE_MAX == size) {
// conversion failure - should not happen