From 687bf8211ff639c08b1fe3936f6dc6f37ff2e3e5 Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Mon, 8 Jun 2015 18:06:44 +0300 Subject: [PATCH] Don't use -1 as buffer length --- tinyxml2.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index fde1801..6fbbf16 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -2041,12 +2041,16 @@ void XMLPrinter::Print( const char* format, ... ) #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) #if defined(WINCE) int len = 512; - do { + for (;;) { len = len*2; char* str = new char[len](); - len = _vsnprintf(str, len, format, va); + const int required = _vsnprintf(str, len, format, va); delete[] str; - }while (len < 0); + if ( required != -1 ) { + len = required; + break; + } + } #else int len = _vscprintf( format, va ); #endif