avoid multiple reallocations in wxString::PrintfV() if vsnprintf() returns the total required size

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36303 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2005-11-30 14:49:47 +00:00
parent 42413abf11
commit de2589be08

View File

@@ -1813,7 +1813,7 @@ int wxString::PrintfV(const wxChar* pszFormat, va_list argptr)
for ( ;; )
{
wxStringBuffer tmp(*this, size + 1);
wxChar* buf = tmp;
wxChar *buf = tmp;
if ( !buf )
{
@@ -1836,14 +1836,20 @@ int wxString::PrintfV(const wxChar* pszFormat, va_list argptr)
// vsnprintf() may return either -1 (traditional Unix behaviour) or the
// total number of characters which would have been written if the
// buffer were large enough (newer standards such as Unix98)
if ( len >= 0 && len <= size )
if ( len < 0 )
{
// still not enough, as we don't know how much we need, double the
// current size of the buffer
size *= 2;
}
else if ( len > size )
{
size = len;
}
else // ok, there was enough space
{
// ok, there was enough space
break;
}
// still not enough, double it again
size *= 2;
}
// we could have overshot