From 0a794f390f597447d8b8411c9e5d5ee7fb22ba76 Mon Sep 17 00:00:00 2001 From: Eric House Date: Fri, 28 Jun 2013 18:47:11 -0700 Subject: [PATCH] fix off-by-one error leading to malformed queries --- xwords4/relay/xwrelay.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/xwords4/relay/xwrelay.cpp b/xwords4/relay/xwrelay.cpp index 05c7a8ece..d6572102c 100644 --- a/xwords4/relay/xwrelay.cpp +++ b/xwords4/relay/xwrelay.cpp @@ -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 {