From 73f507f52d91365eb93c085c25fe573e84cc1075 Mon Sep 17 00:00:00 2001 From: =?utf8?q?W=C5=82odzimierz=20Skiba?= Date: Mon, 4 Jul 2005 11:12:52 +0000 Subject: [PATCH] Prevent crash in wxString::Mid under STL builds (fixes #1231725). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34811 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/string.cpp | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/common/string.cpp b/src/common/string.cpp index be45802169..cded294536 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -1397,32 +1397,33 @@ const wxCharBuffer wxString::ToAscii() const // extract string of length nCount starting at nFirst wxString wxString::Mid(size_t nFirst, size_t nCount) const { - size_t nLen = length(); + size_t nLen = length(); - // default value of nCount is npos and means "till the end" - if ( nCount == npos ) - { - nCount = nLen - nFirst; - } + // default value of nCount is npos and means "till the end" + if ( nCount == npos ) + { + nCount = nLen - nFirst; + } - // out-of-bounds requests return sensible things - if ( nFirst + nCount > nLen ) - { - nCount = nLen - nFirst; - } + // out-of-bounds requests return sensible things + if ( nFirst + nCount > nLen ) + { + nCount = nLen - nFirst; + } - if ( nFirst > nLen ) - { - // AllocCopy() will return empty string - nCount = 0; - } + if ( nFirst > nLen ) + { + // AllocCopy() will return empty string + return wxEmptyString; + } - wxString dest(*this, nFirst, nCount); - if ( dest.length() != nCount ) { - wxFAIL_MSG( _T("out of memory in wxString::Mid") ); - } + wxString dest(*this, nFirst, nCount); + if ( dest.length() != nCount ) + { + wxFAIL_MSG( _T("out of memory in wxString::Mid") ); + } - return dest; + return dest; } // check that the string starts with prefix and return the rest of the string -- 2.45.2