mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
fix off-by-one error leading to malformed queries
This commit is contained in:
parent
3f2548dcce
commit
0a794f390f
1 changed files with 5 additions and 5 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue