diff --git a/include/wx/string.h b/include/wx/string.h index a648beb6d7..cb6cf460a0 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -431,7 +431,10 @@ private: size_t len; SubstrBufFromType(const T& data_, size_t len_) - : data(data_), len(len_) {} + : data(data_), len(len_) + { + wxASSERT_MSG( len != npos, "must have real length" ); + } }; #if wxUSE_UNICODE_UTF8 diff --git a/src/common/string.cpp b/src/common/string.cpp index a287759822..e68c7f03c0 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -369,6 +369,9 @@ wxString::SubstrBufFromMB wxString::ConvertStr(const char *psz, size_t nLength, // UTF-8 sequence and psz may be invalid: if ( wxStringOperations::IsValidUtf8String(psz, nLength) ) { + // we must pass the real string length to SubstrBufFromMB ctor + if ( nLength == npos ) + nLength = psz ? strlen(psz) : 0; return SubstrBufFromMB(wxCharBuffer::CreateNonOwned(psz), nLength); } // else: do the roundtrip through wchar_t*