fix for always terminating intermediate UniChar String for 4 bytes wchar_t
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@26130 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1331,13 +1331,16 @@ public:
|
|||||||
}
|
}
|
||||||
ByteCount byteBufferLen = n * sizeof( UniChar ) ;
|
ByteCount byteBufferLen = n * sizeof( UniChar ) ;
|
||||||
#if SIZEOF_WCHAR_T == 4
|
#if SIZEOF_WCHAR_T == 4
|
||||||
ubuf = (UniChar*) malloc( byteBufferLen ) ;
|
ubuf = (UniChar*) malloc( byteBufferLen + 2 ) ;
|
||||||
#else
|
#else
|
||||||
ubuf = (UniChar*) (buf ? buf : tbuf) ;
|
ubuf = (UniChar*) (buf ? buf : tbuf) ;
|
||||||
#endif
|
#endif
|
||||||
status = TECConvertText(m_MB2WC_converter, (ConstTextPtr) psz , byteInLen, &byteInLen,
|
status = TECConvertText(m_MB2WC_converter, (ConstTextPtr) psz , byteInLen, &byteInLen,
|
||||||
(TextPtr) ubuf , byteBufferLen, &byteOutLen);
|
(TextPtr) ubuf , byteBufferLen, &byteOutLen);
|
||||||
#if SIZEOF_WCHAR_T == 4
|
#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 ;
|
wxMBConvUTF16BE converter ;
|
||||||
res = converter.MB2WC( (buf ? buf : tbuf) , (const char*)ubuf , n ) ;
|
res = converter.MB2WC( (buf ? buf : tbuf) , (const char*)ubuf , n ) ;
|
||||||
free( ubuf ) ;
|
free( ubuf ) ;
|
||||||
|
Reference in New Issue
Block a user