From: Vadim Zeitlin Date: Mon, 27 Nov 2006 15:03:06 +0000 (+0000) Subject: NUL terminate the string in UngetWriteBuf(len) (bug 1594189) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/c56d73fe00d724fc3bba1eb9e22c584434c0dff4 NUL terminate the string in UngetWriteBuf(len) (bug 1594189) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43685 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/string.cpp b/src/common/string.cpp index 7d77c76f8f..2a98946787 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -1077,16 +1077,21 @@ wxChar *wxString::GetWriteBuf(size_t nLen) // put string back in a reasonable state after GetWriteBuf void wxString::UngetWriteBuf() { - GetStringData()->nDataLength = wxStrlen(m_pchData); - GetStringData()->Validate(true); + UngetWriteBuf(wxStrlen(m_pchData)); } void wxString::UngetWriteBuf(size_t nLen) { - GetStringData()->nDataLength = nLen; - GetStringData()->Validate(true); + wxStringData * const pData = GetStringData(); + + wxASSERT_MSG( nLen < pData->nAllocLength, _T("buffer overrun") ); + + // the strings we store are always NUL-terminated + pData->data()[nLen] = _T('\0'); + pData->nDataLength = nLen; + pData->Validate(true); } -#endif +#endif // !wxUSE_STL // --------------------------------------------------------------------------- // data access