From c2cd367f7dc5ce7e6a25d2ab778b4fe6e210e312 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 28 Dec 2011 13:51:13 +0000 Subject: [PATCH] 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 --- src/common/stringimpl.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/common/stringimpl.cpp b/src/common/stringimpl.cpp index ed9a83e476..498793722e 100644 --- a/src/common/stringimpl.cpp +++ b/src/common/stringimpl.cpp @@ -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'); } -- 2.45.2