X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f3a355ceb36ffe85b44609b3279505f4ea07a533..73fe67bd60b57f95dc63809f7843ed2a15928436:/src/common/strconv.cpp diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp index 487b2204aa..4b2a491e13 100644 --- a/src/common/strconv.cpp +++ b/src/common/strconv.cpp @@ -71,9 +71,9 @@ #include "wx/fontmap.h" #ifdef __WXMAC__ -#include "ATSUnicode.h" -#include "TextCommon.h" -#include "TextEncodingConverter.h" +#include +#include +#include #include "wx/mac/private.h" // includes mac headers #endif @@ -1331,13 +1331,16 @@ public: } ByteCount byteBufferLen = n * sizeof( UniChar ) ; #if SIZEOF_WCHAR_T == 4 - ubuf = (UniChar*) malloc( byteBufferLen ) ; + ubuf = (UniChar*) malloc( byteBufferLen + 2 ) ; #else ubuf = (UniChar*) (buf ? buf : tbuf) ; #endif status = TECConvertText(m_MB2WC_converter, (ConstTextPtr) psz , byteInLen, &byteInLen, (TextPtr) ubuf , byteBufferLen, &byteOutLen); #if SIZEOF_WCHAR_T == 4 + // we have to terminate here, because n might be larger for the trailing zero, and if UniChar + // is not properly terminated we get random characters at the end + ubuf[byteOutLen / sizeof( UniChar ) ] = 0 ; wxMBConvUTF16BE converter ; res = converter.MB2WC( (buf ? buf : tbuf) , (const char*)ubuf , n ) ; free( ubuf ) ; @@ -1373,9 +1376,9 @@ public: #if SIZEOF_WCHAR_T == 4 wxMBConvUTF16BE converter ; size_t unicharlen = converter.WC2MB( NULL , psz , 0 ) ; - byteBufferLen = unicharlen ; - ubuf = (UniChar*) malloc( byteBufferLen + 2 ) ; - converter.WC2MB( (char*) ubuf , psz, unicharlen ) ; + byteInLen = unicharlen ; + ubuf = (UniChar*) malloc( byteInLen + 2 ) ; + converter.WC2MB( (char*) ubuf , psz, unicharlen + 2 ) ; #else ubuf = (UniChar*) psz ; #endif