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
This commit is contained in:
Vadim Zeitlin
2008-04-14 16:05:50 +00:00
parent 87be8ad315
commit 77a0f3d154

View File

@@ -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);