]> git.saurik.com Git - wxWidgets.git/commitdiff
NUL terminate the string in UngetWriteBuf(len) (bug 1594189)
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 27 Nov 2006 15:03:06 +0000 (15:03 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 27 Nov 2006 15:03:06 +0000 (15:03 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43685 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/string.cpp

index 7d77c76f8f9a188f70129eb8571bf3e82546c8d1..2a989467876a4c82b3dfe172459a1165019b5ae3 100644 (file)
@@ -1077,16 +1077,21 @@ wxChar *wxString::GetWriteBuf(size_t nLen)
 // put string back in a reasonable state after GetWriteBuf
 void wxString::UngetWriteBuf()
 {
 // 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)
 {
 }
 
 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
 
 // ---------------------------------------------------------------------------
 // data access