X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cd0b170911637899ac3c126367ee5821f357c185..31e78e0cb6e8463c43349502b78c8095a0021d00:/src/common/string.cpp diff --git a/src/common/string.cpp b/src/common/string.cpp index 917e979231..f37934d939 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -360,8 +360,13 @@ wxString::wxString(const wchar_t *pwz) // allocates memory needed to store a C string of length nLen void wxString::AllocBuffer(size_t nLen) { - wxASSERT( nLen > 0 ); // - wxASSERT( nLen <= INT_MAX-1 ); // max size (enough room for 1 extra) + // allocating 0 sized buffer doesn't make sense, all empty strings should + // reuse g_strEmpty + wxASSERT( nLen > 0 ); + + // make sure that we don't overflow + wxASSERT( nLen < (INT_MAX / sizeof(wxChar)) - + (sizeof(wxStringData) + EXTRA_ALLOC + 1) ); STATISTICS_ADD(Length, nLen); @@ -1072,36 +1077,31 @@ bool wxString::ToDouble(double *val) const } // --------------------------------------------------------------------------- -// stream-like operators +// formatted output // --------------------------------------------------------------------------- -wxString& wxString::operator<<(int i) + +/* static */ +wxString wxString::Format(const wxChar *pszFormat, ...) { - wxString res; - res.Printf(wxT("%d"), i); + va_list argptr; + va_start(argptr, pszFormat); - return (*this) << res; -} + wxString s; + s.PrintfV(pszFormat, argptr); -wxString& wxString::operator<<(float f) -{ - wxString res; - res.Printf(wxT("%f"), f); + va_end(argptr); - return (*this) << res; + return s; } -wxString& wxString::operator<<(double d) +/* static */ +wxString wxString::FormatV(const wxChar *pszFormat, va_list argptr) { - wxString res; - res.Printf(wxT("%g"), d); - - return (*this) << res; + wxString s; + s.Printf(pszFormat, argptr); + return s; } -// --------------------------------------------------------------------------- -// formatted output -// --------------------------------------------------------------------------- - int wxString::Printf(const wxChar *pszFormat, ...) { va_list argptr; @@ -1780,20 +1780,8 @@ void wxArrayString::Copy(const wxArrayString& src) if ( src.m_nCount > ARRAY_DEFAULT_INITIAL_SIZE ) Alloc(src.m_nCount); - // we can't just copy the pointers here because otherwise we would share - // the strings with another array because strings are ref counted -#if 0 - if ( m_nCount != 0 ) - memcpy(m_pItems, src.m_pItems, m_nCount*sizeof(wxChar *)); -#endif // 0 - for ( size_t n = 0; n < src.m_nCount; n++ ) Add(src[n]); - - // if the other array is auto sorted too, we're already sorted, but - // otherwise we should rearrange the items - if ( m_autoSort && !src.m_autoSort ) - Sort(); } // grow the array