tinyxml2 icon indicating copy to clipboard operation
tinyxml2 copied to clipboard

XMLDocument::ErrorStr() returns empty string in some cases

Open alabuzhev opened this issue 7 years ago • 3 comments

XMLDocument::SetError() implementation creates a "long form" error description only if format is provided. However, in about dozen cases SetError is called with format set to 0 (example), rendering ErrorStr() & PrintError() useless.

Is it intentional? It feels like it was supposed to be something like this instead:

diff --git a/tinyxml2.cpp b/tinyxml2.cpp
index 04cf697..d0a66ee 100755
--- a/tinyxml2.cpp
+++ b/tinyxml2.cpp
@@ -2305,20 +2305,20 @@ void XMLDocument::SetError( XMLError error, int lineNum, const char* format, ...
     _errorLineNum = lineNum;
 	_errorStr.Reset();
 
-    if (format) {
         size_t BUFFER_SIZE = 1000;
         char* buffer = new char[BUFFER_SIZE];
         TIXML_SNPRINTF(buffer, BUFFER_SIZE, "Error=%s ErrorID=%d (0x%x) Line number=%d: ", ErrorIDToName(error), int(error), int(error), lineNum);
         size_t len = strlen(buffer);
 
+    if (format) {
         va_list va;
         va_start( va, format );
         TIXML_VSNPRINTF( buffer + len, BUFFER_SIZE - len, format, va );
         va_end( va );
+    }
 
         _errorStr.SetStr(buffer);
         delete [] buffer;
-    }
 }
  • i.e. always create a "basic" description and append some custom data, if provided.

Thanks.

alabuzhev avatar Dec 20 '17 00:12 alabuzhev

Good point. Marking enhancement.

leethomason avatar Dec 20 '17 22:12 leethomason

Thanks. Related question: after aa18839 error messages are less detailed - the xml content isn't displayed anymore here and in some other places. Is it intentional?

alabuzhev avatar Jan 06 '18 18:01 alabuzhev

Possible I missed some. Re-opening to check.

leethomason avatar Jan 12 '18 00:01 leethomason