fix crashes due to missing npos handling in several wxString methods in STL build (bug 1941352); add an assert to ensure this bug doesn't occur in the future
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53161 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -431,7 +431,10 @@ private:
|
|||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
SubstrBufFromType(const T& data_, 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
|
#if wxUSE_UNICODE_UTF8
|
||||||
|
@@ -369,6 +369,9 @@ wxString::SubstrBufFromMB wxString::ConvertStr(const char *psz, size_t nLength,
|
|||||||
// UTF-8 sequence and psz may be invalid:
|
// UTF-8 sequence and psz may be invalid:
|
||||||
if ( wxStringOperations::IsValidUtf8String(psz, nLength) )
|
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);
|
return SubstrBufFromMB(wxCharBuffer::CreateNonOwned(psz), nLength);
|
||||||
}
|
}
|
||||||
// else: do the roundtrip through wchar_t*
|
// else: do the roundtrip through wchar_t*
|
||||||
|
Reference in New Issue
Block a user