Remember to fill in new char's.

...we seriously need to use a standard <string>.

*glares at Yaniel*
This commit is contained in:
Jason Felds
2015-09-26 21:03:46 -04:00
parent d878a44a9b
commit 537af8d866
5 changed files with 30 additions and 16 deletions
+12 -6
View File
@@ -469,6 +469,7 @@ RString vssprintf( const char *szFormat, va_list argList )
va_end(tmp);
char *buf = new char[iNeeded + 1];
std::fill(buf, buf + iNeeded + 1, '\0');
vsnprintf( buf, iNeeded+1, szFormat, argList );
RString ret(buf);
delete [] buf;
@@ -477,22 +478,27 @@ RString vssprintf( const char *szFormat, va_list argList )
int iChars = FMT_BLOCK_SIZE;
int iTry = 1;
char *buf = new char[iChars];
for (;;)
{
// Grow more than linearly (e.g. 512, 1536, 3072, etc)
char *buf = new char[iChars];
std::fill(buf, buf + iChars, '\0');
int used = vsnprintf( buf, iChars - 1, szFormat, argList );
if ( used == -1 )
{
iChars += ( ++iTry * FMT_BLOCK_SIZE );
delete [] buf;
continue;
}
else
{
/* OK */
sStr.assign(buf, used);
}
/* OK */
sStr.assign( buf, used );
delete [] buf;
break;
if (used != -1)
{
break;
}
}
#endif
return sStr;