X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9129836e627b31134dd2a1e8671a0906883a063a..7528971e6bd0745f2e9f2234fc8e63235f0dba3a:/src/common/string.cpp diff --git a/src/common/string.cpp b/src/common/string.cpp index 8a722a4f4c..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 @@ -1682,17 +1687,11 @@ int wxString::Find(const wxChar *pszSub) const // the implementation of all the functions below is exactly the same so factor // it out -#ifdef __WATCOMC__ - #define STR2INTLINK _WCRTLINK -#else - #define STR2INTLINK -#endif - -template +template bool wxStringToIntType(const wxChar *start, T *val, int base, - T STR2INTLINK (*func)(const wxChar *, wxChar **, int)) + F func) { wxCHECK_MSG( val, false, _T("NULL output pointer") ); wxASSERT_MSG( !base || (base > 1 && base <= 36), _T("invalid base") );