mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-03 23:04:08 +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, ... )
|
string_printf( string& str, const char* fmt, ... )
|
||||||
{
|
{
|
||||||
const int origsiz = str.size();
|
const int origsiz = str.size();
|
||||||
int newsiz = 100;
|
int addsiz = 100;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
for ( ; ; ) {
|
for ( ; ; ) {
|
||||||
str.resize( origsiz + newsiz );
|
str.resize( origsiz + addsiz );
|
||||||
|
|
||||||
va_start( ap, fmt );
|
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 );
|
va_end( ap );
|
||||||
|
|
||||||
if ( len > newsiz ) { // needs more space
|
if ( len >= addsiz ) { // needs more space
|
||||||
newsiz = len + 1;
|
addsiz = len + 1;
|
||||||
} else if ( -1 == len ) {
|
} else if ( -1 == len ) {
|
||||||
assert(0); // should be impossible
|
assert(0); // should be impossible
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue