Boost C++ Libraries: Ticket #11848: Win32 backend bug when do wide char convert to multi byte in boost::locale https://svn.boost.org/trac10/ticket/11848 <p> The function wide_to_multibyte_non_zero in locale/src/encoding/wconv_codepage.ipp has bug. This function assume that when the codepage is CP_UTF7 or CP_UTF8, the substitute_ptr and subst_char_ptr will be 0. But, in x64 Windows 10, I use codepage 54936 get 87 error code after the first <a class="missing wiki">WideCharToMultiByte</a> called. This will make n is zero, and the second <a class="missing wiki">WideCharToMultiByte</a> call will make the program crash. </p> <p> In MSDN shipped with Visual Studio .NET 2003 it is said that parameters lpDefaultChar and lpUsedDefaultChar must be NULL not only for CP_UTF7 and CP_UTF8, but also for all codepages mentioned in notes for dwFlags parameter: </p> <blockquote> <p> 50220 50221 50222 50225 50227 50229 57002 through 57011 65000 (UTF-7) 42 (Symbol) </p> </blockquote> <blockquote> <p> It is still true as of Windows 8 &amp; 10: if you try to call </p> </blockquote> <p> BOOL bVal = FALSE; </p> <p> <a class="missing wiki">WideCharToMultiByte</a>(50220, 0, L"asdf", 4, NULL, 0, NULL, &amp;bVal); </p> <p> You'll get 0 with <a class="missing wiki">GetLastError</a> 87 (ERROR_INVALID_PARAMETER). </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11848 Trac 1.4.3 Artyom Beilis Wed, 16 Dec 2015 11:47:20 GMT status changed https://svn.boost.org/trac10/ticket/11848#comment:1 https://svn.boost.org/trac10/ticket/11848#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> It contradicts MSDN: </p> <p> <a class="ext-link" href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd374130(v=vs.85).aspx"><span class="icon">​</span>https://msdn.microsoft.com/en-us/library/windows/desktop/dd374130(v=vs.85).aspx</a> </p> <p> (yes I know in comments it is mentioned) </p> <p> Also the reason you crash is because &amp;buf<a class="missing changeset" title="No changeset 0 in the repository">[0]</a> can't be called when n==0 (in first place) </p> <p> I'll look into it. </p> <p> Thanks. </p> Ticket