X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9a83f860948059b0273b5cc6d9e43fadad3ebfca..afab8b85c4bdeb11a248c57d13e9bcfa14149ef8:/src/common/stringimpl.cpp?ds=inline diff --git a/src/common/stringimpl.cpp b/src/common/stringimpl.cpp index 429f3843bd..3dad9eb3c0 100644 --- a/src/common/stringimpl.cpp +++ b/src/common/stringimpl.cpp @@ -4,7 +4,6 @@ // Author: Vadim Zeitlin, Ryan Norton // Modified by: // Created: 29/01/98 -// RCS-ID: $Id$ // Copyright: (c) 1998 Vadim Zeitlin // (c) 2004 Ryan Norton // Licence: wxWindows licence @@ -395,14 +394,14 @@ bool wxStringImpl::Alloc(size_t nLen) wxStringImpl::iterator wxStringImpl::begin() { - if (length() > 0) + if ( !empty() ) CopyBeforeWrite(); return m_pchData; } wxStringImpl::iterator wxStringImpl::end() { - if (length() > 0) + if ( !empty() ) CopyBeforeWrite(); return m_pchData + length(); } @@ -528,7 +527,7 @@ size_t wxStringImpl::rfind(const wxStringImpl& str, size_t nStart) const if ( length() >= str.length() ) { // avoids a corner case later - if ( length() == 0 && str.length() == 0 ) + if ( empty() && str.empty() ) return 0; // "top" is the point where search starts from @@ -681,7 +680,11 @@ bool wxStringImpl::AssignCopy(size_t nSrcLen, // allocation failure handled by caller return false; } - memcpy(m_pchData, pszSrcData, nSrcLen*sizeof(wxStringCharType)); + + // use memmove() and not memcpy() here as we might be copying from our own + // buffer in case of assignment such as "s = s.c_str()" (see #11294) + memmove(m_pchData, pszSrcData, nSrcLen*sizeof(wxStringCharType)); + GetStringData()->nDataLength = nSrcLen; m_pchData[nSrcLen] = wxT('\0'); }