diff --git a/Makefile b/Makefile index a30c8765f..f35d85695 100644 --- a/Makefile +++ b/Makefile @@ -632,7 +632,7 @@ test/testconstructors.o: test/testconstructors.cpp lib/astutils.h lib/check.h li test/testcppcheck.o: test/testcppcheck.cpp lib/analyzerinfo.h lib/check.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/utils.h test/testsuite.h $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o test/testcppcheck.o test/testcppcheck.cpp -test/testerrorlogger.o: test/testerrorlogger.cpp lib/analyzerinfo.h lib/check.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/utils.h test/testsuite.h +test/testerrorlogger.o: test/testerrorlogger.cpp externals/tinyxml2/tinyxml2.h lib/analyzerinfo.h lib/check.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/utils.h test/testsuite.h $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o test/testerrorlogger.o test/testerrorlogger.cpp test/testexceptionsafety.o: test/testexceptionsafety.cpp lib/astutils.h lib/check.h lib/checkexceptionsafety.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h test/testsuite.h diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index 5c1c65059..4aeba864c 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -216,7 +216,7 @@ ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errmsg) const char *info = strinfo ? strinfo : ""; const int line = strline ? std::atoi(strline) : 0; const int column = strcolumn ? std::atoi(strcolumn) : 0; - callStack.emplace_back(file, info, line, column); + callStack.emplace_front(file, info, line, column); } } } diff --git a/test/testerrorlogger.cpp b/test/testerrorlogger.cpp index c4d14c637..c8d1ccd26 100644 --- a/test/testerrorlogger.cpp +++ b/test/testerrorlogger.cpp @@ -22,6 +22,7 @@ #include "suppressions.h" #include "testsuite.h" +#include #include #include @@ -49,6 +50,7 @@ private: TEST_CASE(ToXmlV2); TEST_CASE(ToXmlV2Locations); TEST_CASE(ToXmlV2Encoding); + TEST_CASE(FromXmlV2); // Inconclusive results in xml reports.. TEST_CASE(InconclusiveXml); @@ -231,6 +233,38 @@ private: } } + void FromXmlV2() const { + const char xmldata[] = "\n" + "\n" + " \n" + " \n" + ""; + tinyxml2::XMLDocument doc; + doc.Parse(xmldata, sizeof(xmldata)); + ErrorMessage msg(doc.FirstChildElement()); + ASSERT_EQUALS("errorId", msg.id); + ASSERT_EQUALS(Severity::error, msg.severity); + ASSERT_EQUALS(123u, msg.cwe.id); + ASSERT_EQUALS(Certainty::inconclusive, msg.certainty); + ASSERT_EQUALS("Programming error.", msg.shortMessage()); + ASSERT_EQUALS("Verbose error", msg.verboseMessage()); + ASSERT_EQUALS(456u, msg.hash); + ASSERT_EQUALS(2u, msg.callStack.size()); + ASSERT_EQUALS("foo.cpp", msg.callStack.front().getfile()); + ASSERT_EQUALS(5, msg.callStack.front().line); + ASSERT_EQUALS(2u, msg.callStack.front().column); + ASSERT_EQUALS("bar.cpp", msg.callStack.back().getfile()); + ASSERT_EQUALS(8, msg.callStack.back().line); + ASSERT_EQUALS(1u, msg.callStack.back().column); + } + void InconclusiveXml() const { // Location std::list locs(1, fooCpp5);