fix off-by-one error leading to malformed queries

This commit is contained in:
Eric House 2013-06-28 18:47:11 -07:00
parent 3f2548dcce
commit 0a794f390f

View file

@ -1428,17 +1428,17 @@ void
string_printf( string& str, const char* fmt, ... )
{
const int origsiz = str.size();
int newsiz = 100;
int addsiz = 100;
va_list ap;
for ( ; ; ) {
str.resize( origsiz + newsiz );
str.resize( origsiz + addsiz );
va_start( ap, fmt );
int len = vsnprintf( (char *)str.c_str() + origsiz, newsiz, fmt, ap );
int len = vsnprintf( (char *)str.c_str() + origsiz, addsiz, fmt, ap );
va_end( ap );
if ( len > newsiz ) { // needs more space
newsiz = len + 1;
if ( len >= addsiz ) { // needs more space
addsiz = len + 1;
} else if ( -1 == len ) {
assert(0); // should be impossible
} else {