From 95f687b1f12356c8039d99d034d93fb3df515c3d Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Fri, 23 Mar 2018 20:56:46 +0300 Subject: [PATCH] Cleanup ErrorName() tests * clarify what is being tested to avoid duplicate lines in output * prevent optimizations based on undefined behavior --- xmltest.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/xmltest.cpp b/xmltest.cpp index 90fdd8c..0c495c9 100644 --- a/xmltest.cpp +++ b/xmltest.cpp @@ -1984,8 +1984,14 @@ int main( int argc, const char ** argv ) for( int i = 0; i < XML_ERROR_COUNT; i++ ) { const XMLError error = static_cast(i); const char* name = XMLDocument::ErrorIDToName(error); - XMLTest( "ErrorName() after ClearError()", true, name != 0 ); - XMLTest( "ErrorName() after ClearError()", true, strlen(name) > 0 ); + XMLTest( "ErrorName() not null after ClearError()", true, name != 0 ); + if( name == 0 ) { + // passing null pointer into strlen() is undefined behavior, so + // compiler is allowed to optimise away the null test above if it's + // as reachable as the strlen() call + continue; + } + XMLTest( "ErrorName() not empty after ClearError()", true, strlen(name) > 0 ); } }