Fix return value of wxMBConvUTF32::cWC2MB() in presence of surrogates

UTF-32 conversions only estimate, from above, the size of the output buffer
needed, so the value returned from the first call to FromWChar(NULL) in
cWC2MB() can be inexact for them and we need to return the value returned by
the second call to FromWChar() doing the real conversion from cWC2MB() itself
to ensure that we return the correct output length.

See #17070.
This commit is contained in:
Vadim Zeitlin 2015-11-13 18:00:43 +01:00
parent 048ba4b509
commit 5cff8c1232

View File

@ -488,7 +488,12 @@ wxMBConv::cWC2MB(const wchar_t *inBuff, size_t inLen, size_t *outLen) const
// the input is not
wxCharBuffer buf(dstLen + nulLen - 1);
memset(buf.data() + dstLen, 0, nulLen);
if ( FromWChar(buf.data(), dstLen, inBuff, inLen) != wxCONV_FAILED )
// Notice that return value of the call to FromWChar() here may be
// different from the one above as it could have overestimated the
// space needed, while what we get here is the exact length.
dstLen = FromWChar(buf.data(), dstLen, inBuff, inLen);
if ( dstLen != wxCONV_FAILED )
{
if ( outLen )
{