X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fbf0c83d3c46922f1444423bbc0d8b6614169e13..5ea6dbbfff67d1dfad08044ab721ba56425ef6e1:/src/common/string.cpp diff --git a/src/common/string.cpp b/src/common/string.cpp index 3606bb9e55..ed777353a7 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -107,7 +107,7 @@ extern const wxChar WXDLLEXPORT *wxEmptyString = &g_strEmpty.dummy; // function wxVsnprintfA (A for ANSI), should also find one for Unicode // strings in Unicode build #ifdef __WXMSW__ - #ifdef __VISUALC__ + #if defined(__VISUALC__) || defined(wxUSE_NORLANDER_HEADERS) #define wxVsnprintfA _vsnprintf #endif #else // !Windows @@ -200,7 +200,15 @@ extern int WXDLLEXPORT wxVsnprintf(wxChar *buf, size_t len, return iLen; #else // ANSI - return wxVsnprintfA(buf, len, format, argptr); + // vsnprintf() will not terminate the string with '\0' if there is not + // enough place, but we want the string to always be NUL terminated + int rc = wxVsnprintfA(buf, len - 1, format, argptr); + if ( rc == -1 ) + { + buf[len] = 0; + } + + return rc; #endif // Unicode/ANSI } @@ -1635,17 +1643,6 @@ size_t wxString::find_last_not_of(wxChar ch, size_t nStart) const return npos; } -wxString wxString::substr(size_t nStart, size_t nLen) const -{ - // npos means 'take all' - if ( nLen == npos ) - nLen = 0; - - wxASSERT( nStart + nLen <= Len() ); - - return wxString(c_str() + nStart, nLen == npos ? 0 : nLen); -} - wxString& wxString::erase(size_t nStart, size_t nLen) { wxString strTmp(c_str(), nStart);