From 9f81ac16f01c4c643bb3c8a12227e93dd1947146 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 5 Jul 2015 16:58:13 +0200 Subject: [PATCH] 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. --- src/stc/PlatWX.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index 98cde26a90..dbd2397134 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -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; }