Use memmove() instead of memcpy() in wxString::AssignCopy().

This at least allows the code like "s = s.c_str()" to work correctly when
using our own wxString implementation, even it doesn't fix all
self-assignment-related bugs (again, when using our own implementation only,
there is no bug when using std::basic_string as underlying implementation).

This is a cherry pick of r63008 from 2.8 branch.

See #11245.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70150 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2011-12-28 13:51:13 +00:00
parent d296f9a114
commit c2cd367f7d

View File

@ -681,7 +681,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');
}