From: Vadim Zeitlin Date: Thu, 17 Dec 1998 20:23:13 +0000 (+0000) Subject: wxString::Truncates() now doesn't change the sharied copies of the string X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/79a773ba60af80fece4ddbd346340ef5d4f24a10?ds=sidebyside wxString::Truncates() now doesn't change the sharied copies of the string git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1226 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/string.cpp b/src/common/string.cpp index 749a952b34..77026933c0 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -899,8 +899,13 @@ wxString& wxString::Pad(size_t nCount, char chPad, bool bFromRight) // truncate the string wxString& wxString::Truncate(size_t uiLen) { - *(m_pchData + uiLen) = '\0'; - GetStringData()->nDataLength = uiLen; + if ( uiLen < Len() ) { + CopyBeforeWrite(); + + *(m_pchData + uiLen) = '\0'; + GetStringData()->nDataLength = uiLen; + } + //else: nothing to do, string is already short enough return *this; }