X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b2c31089c2bd10eb5a33f4d43654e85b7ca451f0..4b32f8c79e13296b23a5ca95114e8db2c313f053:/src/common/string.cpp 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