X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/266b635a2862975cb4a470e72d6d4d2f8e637f14..5ea6dbbfff67d1dfad08044ab721ba56425ef6e1:/src/common/string.cpp diff --git a/src/common/string.cpp b/src/common/string.cpp index 9582bca6d9..ed777353a7 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -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);