From 1dd156789cc688f51a66f0bbb322fa625a92086b Mon Sep 17 00:00:00 2001
From: Scott Snyder <scott.snyder@cern.ch>
Date: Thu, 30 Jun 2016 18:43:33 +0200
Subject: [PATCH] 'Suppress cppcheck warning.' (XMLCoreParser-00-01-20)

	* Tagging XMLCoreParser-00-01-20.
	* src/ExpatCoreParser.cxx (do_comment): Suppress cppcheck warning.

	* Tagging XMLCoreParser-00-01-19.
	* Fix tests for cmake build.
---
 Tools/XMLCoreParser/CMakeLists.txt          | 6 ++++--
 Tools/XMLCoreParser/cmt/requirements        | 2 --
 Tools/XMLCoreParser/src/ExpatCoreParser.cxx | 4 ++++
 Tools/XMLCoreParser/test/example1_test.cxx  | 7 ++++++-
 Tools/XMLCoreParser/test/example2_test.cxx  | 9 +++++++--
 5 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/Tools/XMLCoreParser/CMakeLists.txt b/Tools/XMLCoreParser/CMakeLists.txt
index ce03fc54ca30..a47f651d44ba 100644
--- a/Tools/XMLCoreParser/CMakeLists.txt
+++ b/Tools/XMLCoreParser/CMakeLists.txt
@@ -25,13 +25,15 @@ atlas_add_test( example1_test
                 SOURCES
                 test/example1_test.cxx
                 INCLUDE_DIRS ${EXPAT_INCLUDE_DIRS}
-                LINK_LIBRARIES ${EXPAT_LIBRARIES} TestTools XMLCoreParser )
+                LINK_LIBRARIES ${EXPAT_LIBRARIES} TestTools XMLCoreParser
+                ENVIRONMENT "XMLCOREPARSER_DATA=${CMAKE_CURRENT_SOURCE_DIR}/data" )
 
 atlas_add_test( example2_test
                 SOURCES
                 test/example2_test.cxx
                 INCLUDE_DIRS ${EXPAT_INCLUDE_DIRS}
-                LINK_LIBRARIES ${EXPAT_LIBRARIES} TestTools XMLCoreParser )
+                LINK_LIBRARIES ${EXPAT_LIBRARIES} TestTools XMLCoreParser
+                ENVIRONMENT "XMLCOREPARSER_DATA=${CMAKE_CURRENT_SOURCE_DIR}/data" )
 
 atlas_add_executable( example4
                       doc/example4.cxx
diff --git a/Tools/XMLCoreParser/cmt/requirements b/Tools/XMLCoreParser/cmt/requirements
index 617018498319..dee651ae9ca0 100755
--- a/Tools/XMLCoreParser/cmt/requirements
+++ b/Tools/XMLCoreParser/cmt/requirements
@@ -31,5 +31,3 @@ macro texpatlinkopts "" WIN32 " $(cmt_installarea_linkopts) $(Expat_linkopts) "
 
 application texpat texpat.cxx DOMNode.cxx ExpatCoreParser.cxx 
 macro texpat_dependencies XMLCoreParser
-
-
diff --git a/Tools/XMLCoreParser/src/ExpatCoreParser.cxx b/Tools/XMLCoreParser/src/ExpatCoreParser.cxx
index d1dcd37d6f1a..3b922d3c2780 100755
--- a/Tools/XMLCoreParser/src/ExpatCoreParser.cxx
+++ b/Tools/XMLCoreParser/src/ExpatCoreParser.cxx
@@ -256,6 +256,10 @@ void ExpatCoreParser::do_comment (const XML_Char* s)
     {
       std::cout << "ExpatCoreParser::do_comment> s=" << s << " top=" << m_top << " last=" << m_last << " node=" << node << std::endl; 
     }
+
+  // Node is owned by m_last.
+  // cppcheck-suppress memleak
+  node = nullptr;
 }
 
 int ExpatCoreParser::generic_parse (XML_Parser p, const std::string& file_name)
diff --git a/Tools/XMLCoreParser/test/example1_test.cxx b/Tools/XMLCoreParser/test/example1_test.cxx
index 42786a80f4b2..114d8216eadc 100755
--- a/Tools/XMLCoreParser/test/example1_test.cxx
+++ b/Tools/XMLCoreParser/test/example1_test.cxx
@@ -16,9 +16,14 @@ int main (int argc, char* argv[])
   parser.register_external_entity ("LVL1Calorimeter", "NULL");
   parser.register_external_entity ("MuonSpectrometer", "NULL");
 
-  const char* file = "../data/ATLAS_AGDD.xml";
+  const char* dir = getenv("XMLCOREPARSER_DATA");
+  if (!dir)
+    dir = "../data";
+  std::string file = dir;
   if (argc > 1)
     file = argv[1]; 
+  else
+    file += "/ATLAS_AGDD.xml";
 
   parser.parse (file);
   return (0);
diff --git a/Tools/XMLCoreParser/test/example2_test.cxx b/Tools/XMLCoreParser/test/example2_test.cxx
index 2e495e7ff333..a885d07997ce 100755
--- a/Tools/XMLCoreParser/test/example2_test.cxx
+++ b/Tools/XMLCoreParser/test/example2_test.cxx
@@ -48,9 +48,14 @@ int main (int argc, char* argv[])
   p.register_external_entity ("MuonSpectrometer", "NULL");
   p.register_external_entity ("MuonSpectrometer", "");
 
-  const char* file = "../data/ATLAS_AGDD.xml";
-  if (argc > 1) 
+  const char* dir = getenv("XMLCOREPARSER_DATA");
+  if (!dir)
+    dir = "../data";
+  std::string file = dir;
+  if (argc > 1)
     file = argv[1]; 
+  else
+    file += "/ATLAS_AGDD.xml";
  
   p.visit (file); 
   return (0); 
-- 
GitLab