You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by Farid Zaripov <Fa...@kyiv.vdiweb.com> on 2006/10/05 15:42:37 UTC

[PATCH] STDCXX-93

   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.

Re: [PATCH] STDCXX-93

Posted by Martin Sebor <se...@roguewave.com>.
Farid Zaripov wrote:
>   Attached is a patch for resolve issue STDCXX-93.
[...]
> Index: time_put.cpp
> ===================================================================
> --- time_put.cpp	(revision 453153)
> +++ time_put.cpp	(working copy)
> @@ -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);

I don't think this is quite correct (even if it's safe).

The last argument to mbstowcs() is the maximum number of elements
in the destination buffer that the function can write. The length
of the second argument (in bytes) might be greater than the number
of multibyte characters in the string, which in turn might be even
greater than the number of wide characters that correspond to it.

We should either pass in the size of the destination buffer or
some large value that windows can deal with.

Martin