From: Vadim Zeitlin Date: Sat, 31 May 2008 01:53:10 +0000 (+0000) Subject: fix bug with wrong return value in wxMBConv_iconv::ToWChar() introduced by a recent... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/1752fda65bd34f1b16a222664d7297b6363c8e6f fix bug with wrong return value in wxMBConv_iconv::ToWChar() introduced by a recent check in git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53870 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp index 5c239e2728..bb50f19d4b 100644 --- a/src/common/strconv.cpp +++ b/src/common/strconv.cpp @@ -2111,10 +2111,14 @@ wxMBConv_iconv::ToWChar(wchar_t *dst, size_t dstLen, char* bufPtr = (char*)dst; // have destination buffer, convert there + size_t dstLenOrig = dstLen; cres = iconv(m2w, ICONV_CHAR_CAST(&pszPtr), &srcLen, &bufPtr, &dstLen); - res = dstLen - (dstLen / SIZEOF_WCHAR_T); + + // convert the number of bytes converted as returned by iconv to the + // number of (wide) characters converted that we need + res = (dstLenOrig - dstLen) / SIZEOF_WCHAR_T; if (ms_wcNeedsSwap) { @@ -2122,10 +2126,6 @@ wxMBConv_iconv::ToWChar(wchar_t *dst, size_t dstLen, for ( unsigned i = 0; i < res; i++ ) dst[i] = WC_BSWAP(dst[i]); } - - // NUL-terminate the string if there is any space left - if (res < dstLen) - dst[res] = 0; } else // no destination buffer {