strings passed to assign do not need to be null-terminated
This commit is contained in:
@@ -263,21 +263,18 @@ RString vssprintf( const char *szFormat, va_list argList )
|
|||||||
char *pBuf = NULL;
|
char *pBuf = NULL;
|
||||||
int iChars = 1;
|
int iChars = 1;
|
||||||
int iUsed = 0;
|
int iUsed = 0;
|
||||||
size_t iActual = 0;
|
|
||||||
int iTry = 0;
|
int iTry = 0;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
// Grow more than linearly (e.g. 512, 1536, 3072, etc)
|
// Grow more than linearly (e.g. 512, 1536, 3072, etc)
|
||||||
iChars += (iTry+1) * FMT_BLOCK_SIZE;
|
iChars += iTry * FMT_BLOCK_SIZE;
|
||||||
pBuf = (char*) _alloca( sizeof(char)*iChars );
|
pBuf = (char*) _alloca( sizeof(char)*iChars );
|
||||||
iUsed = vsnprintf( pBuf, iChars-1, szFormat, argList );
|
iUsed = vsnprintf( pBuf, iChars-1, szFormat, argList );
|
||||||
|
|
||||||
// Ensure proper NULL termination.
|
|
||||||
iActual = iUsed == -1 ? iChars-1 : min(iUsed, iChars-1);
|
|
||||||
pBuf[iActual+1]= '\0';
|
|
||||||
} while ( iUsed < 0 && iTry++ < MAX_FMT_TRIES );
|
} while ( iUsed < 0 && iTry++ < MAX_FMT_TRIES );
|
||||||
|
|
||||||
|
int iActual = min( iUsed, iChars-1 );
|
||||||
|
|
||||||
// assign whatever we managed to format
|
// assign whatever we managed to format
|
||||||
sStr.assign( pBuf, iActual );
|
sStr.assign( pBuf, iActual );
|
||||||
#else
|
#else
|
||||||
|
|||||||
Reference in New Issue
Block a user