From 5cff8c1232c42266cdcd64c516915bc95292d087 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 13 Nov 2015 18:00:43 +0100 Subject: [PATCH] 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. --- src/common/strconv.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp index c3191201c4..3102294183 100644 --- a/src/common/strconv.cpp +++ b/src/common/strconv.cpp @@ -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 ) {