Fix wx2stc() conversion after upgrade to 3.5.5.

UTF8FromUTF16() now only NUL-terminates the string if there is enough space in
it for the trailing NUL, so pass the correct length of the buffer, including
the last byte reserved for this NUL to this function.

Also allocate one byte less in wxCharBuffer, it was adding 1 extra byte
unnecessarily.

See #16776.
This commit is contained in:
Vadim Zeitlin 2015-07-05 16:58:13 +02:00
parent 2eb04b44df
commit 9f81ac16f0

View File

@ -1643,10 +1643,11 @@ wxWX2MBbuf wx2stc(const wxString& str)
size_t wclen = str.length();
size_t len = UTF8Length(wcstr, wclen);
wxCharBuffer buffer(len+1);
UTF8FromUTF16(wcstr, wclen, buffer.data(), len);
// TODO check NULL termination!!
// The buffer object adds extra byte for the terminating NUL and we must
// pass the total length, including this NUL, to UTF8FromUTF16() to ensure
// that it NULL-terminates the string.
wxCharBuffer buffer(len);
UTF8FromUTF16(wcstr, wclen, buffer.data(), len + 1);
return buffer;
}