On Thursday 18 June 2026 12:36:04 Kirill Makurin wrote:
> Previous implementaion used `wcstombs` to convert its wide string arguments to
> narrow strings, which are then passed to `_assert`; function `wcstombs` is
> thread-unsafe in its nature and should not be used.

It is really truth that wcstombs is thread-unsafe? I had an impression
that wcstombs is using its own thread local buffer, and that it is safe
to use it (I used it many times in this way). So I would like to know
more information.

> Other than thread-safety, `wcstombs` has other issues:
> 
> 1. It uses code page used by active CRT locale; this may be an issue when 
> assert
>   message is displayed in message box, which assumes string to be encoded 
> using
>   active ANSI code page.

Case 1. for sure when displaying to GUI MessageBoxA() it is needed to
use ACP for conversion. But I still think that for fprintf output it
should be used the CRT locale, not the ACP.

> 2. In case when entire string cannot be converted to target code page, it does
>   not allow to convert only part of the string.

This is also good point. WinAPI WideCharToMultiByte() can solve it. Or
if we want to stick with CRT (which I think that it is a good idea for
CRT functions) then loop over wcrtomb() could be used.


_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to