X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6eaebb297a16db33612717a06f576f8606b5132f..5a2e3d8c47db7f95d504ecd45f58b96c56572dd1:/src/common/string.cpp diff --git a/src/common/string.cpp b/src/common/string.cpp index 9a0cff0e00..9b1de655cd 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -970,9 +970,14 @@ wxString::wxString(const char *psz, wxMBConv& conv, size_t nLength) } else { - wxWCharBuffer buf(nLen + 1); + // the input buffer to MB2WC must always be NUL-terminated + wxCharBuffer inBuf(nLen); + memcpy(inBuf.data(), psz, nLen); + inBuf.data()[nLen] = '\0'; + + wxWCharBuffer buf(nLen); // MB2WC wants the buffer size, not the string length hence +1 - nLen = conv.MB2WC(buf.data(), psz, nLen + 1); + nLen = conv.MB2WC(buf.data(), inBuf.data(), nLen + 1); if ( nLen != (size_t)-1 ) {