X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/341e7d28891d72b0f7aee27ca41d5827d261c67b..eda22ec3a2d70fe178a194fe58804fceacb15f4c:/src/common/string.cpp diff --git a/src/common/string.cpp b/src/common/string.cpp index 764d0a41c6..29dc8d60da 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); @@ -1105,14 +1110,15 @@ wxString& wxString::operator<<(double d) /* static */ wxString wxString::Format(const wxChar *pszFormat, ...) { - va_list argptr; - va_start(argptr, pszFormat); + va_list argptr; + va_start(argptr, pszFormat); - wxString s = FormatV(pszFormat, argptr); + wxString s; + s.PrintfV(pszFormat, argptr); - va_end(argptr); + va_end(argptr); - return s; + return s; } /* static */ @@ -1801,20 +1807,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