Sfoglia il codice sorgente

Asserts for formatted output length

Dmitry-Me 10 anni fa
parent
commit
1d32e586d5
1 ha cambiato i file con 5 aggiunte e 1 eliminazioni
  1. 5 1
      tinyxml2.cpp

+ 5 - 1
tinyxml2.cpp

@@ -75,10 +75,12 @@ distribution.
 				const int required = _vsnprintf(str, len, format, va);
 				delete[] str;
 				if ( required != -1 ) {
+					TIXMLASSERT( required >= 0 );
 					len = required;
 					break;
 				}
 			}
+			TIXMLASSERT( len >= 0 );
 			return len;
 		}
 	#endif
@@ -90,6 +92,7 @@ distribution.
 	inline int TIXML_VSCPRINTF( const char* format, va_list va )
 	{
 		int len = vsnprintf( 0, 0, format, va );
+		TIXMLASSERT( len >= 0 );
 		return len;
 	}
 	#define TIXML_SSCANF   sscanf
@@ -2105,9 +2108,10 @@ void XMLPrinter::Print( const char* format, ... )
         vfprintf( _fp, format, va );
     }
     else {
-        int len = TIXML_VSCPRINTF( format, va );
+        const int len = TIXML_VSCPRINTF( format, va );
         // Close out and re-start the va-args
         va_end( va );
+        TIXMLASSERT( len >= 0 );
         va_start( va, format );
         TIXMLASSERT( _buffer.Size() > 0 && _buffer[_buffer.Size() - 1] == 0 );
         char* p = _buffer.PushArr( len ) - 1;	// back up over the null terminator.