From 13b2d734278f95b87f9aef654683c6abf63ef985 Mon Sep 17 00:00:00 2001 From: Sarat Addepalli Date: Tue, 19 May 2015 12:44:57 +0530 Subject: [PATCH] Add null-checks in `XMLTest()` When either `expected` or `found` is `NULL`, `XMLTest()` will segfault on `strcmp()`. This patch adds null-checks, and passes the test if both `expected` and `found` are `NULL`. --- xmltest.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/xmltest.cpp b/xmltest.cpp index 4325cb7..edd2e70 100644 --- a/xmltest.cpp +++ b/xmltest.cpp @@ -30,7 +30,12 @@ int gFail = 0; bool XMLTest (const char* testString, const char* expected, const char* found, bool echo=true, bool extraNL=false ) { - bool pass = !strcmp( expected, found ); + bool pass; + if ( !expected && !found ) + pass = true; + else if ( !expected || !found ) + pass = false; + else pass = !strcmp( expected, found ); if ( pass ) printf ("[pass]"); else