From 77a0f3d154af63737a1e8e2e48a6e014ad58fbcb Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 14 Apr 2008 16:05:50 +0000 Subject: [PATCH] fix bug when appending string to itself (closes bug 1942116) [backport of r48302 from trunk] git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@53167 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/string.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/common/string.cpp b/src/common/string.cpp index e9ca33871f..ea260708d1 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -844,6 +844,16 @@ bool wxStringBase::ConcatSelf(size_t nSrcLen, const wxChar *pszSrcData, size_t nLen = pData->nDataLength; size_t nNewLen = nLen + nSrcLen; + // take special care when appending part of this string to itself: the code + // below reallocates our buffer and this invalidates pszSrcData pointer so + // we have to copy it in another temporary string in this case (but avoid + // doing this unnecessarily) + if ( pszSrcData >= m_pchData && pszSrcData < m_pchData + nLen ) + { + wxStringBase tmp(pszSrcData, nSrcLen); + return ConcatSelf(nSrcLen, tmp.m_pchData, nSrcLen); + } + // alloc new buffer if current is too small if ( pData->IsShared() ) { STATISTICS_ADD(ConcatHit, 0);