From c792fa633252e40052b21ca0e4d68653bc02d2ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Wed, 22 Jul 2026 16:36:36 +0200 Subject: [PATCH 1/6] fix --- lib/suppressions.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index fe483e347fe..b45ba151914 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -136,7 +136,10 @@ std::string SuppressionList::parseXmlFile(const char *filename) s.lineNumber = strToInt(text); else if (std::strcmp(name, "symbolName") == 0) s.symbolName = text; - else if (*text && std::strcmp(name, "hash") == 0) + else if (std::strcmp(name, "macroName") == 0) { + s.macroName = text; + s.type = SuppressionList::Type::macro; + } else if (*text && std::strcmp(name, "hash") == 0) s.hash = strToInt(text); else return std::string("unknown element '") + name + "' in suppressions XML '" + filename + "', expected id/fileName/lineNumber/symbolName/hash."; From ab29d0bbba0d490d3b4b6634a16b2852e7c47fae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Wed, 22 Jul 2026 16:40:45 +0200 Subject: [PATCH 2/6] add parse test --- test/testsuppressions.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/testsuppressions.cpp b/test/testsuppressions.cpp index 90c64eb809e..9cfed2d0336 100644 --- a/test/testsuppressions.cpp +++ b/test/testsuppressions.cpp @@ -1705,6 +1705,27 @@ class TestSuppressions : public TestFixture { ASSERT_EQUALS("sym", suppr.symbolName); } + { + ScopedFile file("suppressparsexml.xml", + "\n" + "\n" + "uninitvar\n" + "file.c\n" + "MACRO_NAME\n" + "\n" + ""); + + SuppressionList supprList; + ASSERT_EQUALS("", supprList.parseXmlFile(file.path().c_str())); + const auto& supprs = supprList.getSuppressions(); + ASSERT_EQUALS(1, supprs.size()); + const auto& suppr = *supprs.cbegin(); + ASSERT_EQUALS("uninitvar", suppr.errorId); + ASSERT_EQUALS("file.c", suppr.fileName); + ASSERT_EQUALS("MACRO_NAME", suppr.macroName); + ASSERT_EQUALS_ENUM(SuppressionList::Type::macro, suppr.type); + } + // no file specified { SuppressionList supprList; From 22b068c564522b46f9ce8ddd3f5c82138f82e124 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Thu, 23 Jul 2026 10:31:04 +0200 Subject: [PATCH 3/6] add helper function for testing xml suppressions --- test/testsuppressions.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/testsuppressions.cpp b/test/testsuppressions.cpp index 9cfed2d0336..92fc60a1c9a 100644 --- a/test/testsuppressions.cpp +++ b/test/testsuppressions.cpp @@ -1779,6 +1779,31 @@ class TestSuppressions : public TestFixture { } } + #define testXmlSuppressions(...) testXmlSuppressions_(__FILE__,__LINE__,__VA_ARGS__) + void testXmlSuppressions_(const char *thisfile, + int thisline, + const std::string &xml, + const std::string &code, + const std::string expected) + { + const char *xmlpath = "testsupressions.xml"; + const char *sourcepath = "test.c"; + + Suppressions supprs; + const ScopedFile xmlfile(xmlpath, xml); + ASSERT_EQUALS_LOC("", supprs.nomsg.parseXmlFile(xmlpath), thisfile, thisline); + + Settings settings; + settings.templateFormat = templateFormat; + settings.quiet = true; + + const FileWithDetails sourcefile(sourcepath, Standards::Language::C, 0); + CppCheck instance(settings, supprs, *this, nullptr, true, nullptr); + instance.checkBuffer(sourcefile, code.c_str(), code.size()); + + ASSERT_EQUALS_LOC(expected, errout_str(), thisfile, thisline); + } + void addSuppressionDuplicate() const { SuppressionList supprs; From a4dbc531072c8da2f06984df34ff25506bbd99d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Thu, 23 Jul 2026 10:31:16 +0200 Subject: [PATCH 4/6] add test --- test/testsuppressions.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/testsuppressions.cpp b/test/testsuppressions.cpp index 92fc60a1c9a..46daff88b9a 100644 --- a/test/testsuppressions.cpp +++ b/test/testsuppressions.cpp @@ -119,6 +119,7 @@ class TestSuppressions : public TestFixture { TEST_CASE(addSuppressionLineMultiple); TEST_CASE(suppressionsParseXmlFile); + TEST_CASE(xmlMacroSuppressions); TEST_CASE(toString); @@ -1804,6 +1805,44 @@ class TestSuppressions : public TestFixture { ASSERT_EQUALS_LOC(expected, errout_str(), thisfile, thisline); } + void xmlMacroSuppressions() + { + testXmlSuppressions( + "\n" + "\n" + "uninitvar\n" + "file.c\n" + "VAR\n" + "\n" + "", + + "#define VAR x\n" + "int f(void) {\n" + " int VAR;\n" + " return VAR;\n" + "}\n", + + "" + ); + testXmlSuppressions( + "\n" + "\n" + "uninitvar\n" + "file.c\n" + "WRONG\n" + "\n" + "", + + "#define VAR x\n" + "int f(void) {\n" + " int VAR;\n" + " return VAR;\n" + "}\n", + + "[test.c:4:12]: (error) Uninitialized variable: x [uninitvar]\n" + ); + } + void addSuppressionDuplicate() const { SuppressionList supprs; From 19109acd6e4f872e0a8790764e2d1be103c3f047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Thu, 23 Jul 2026 15:15:23 +0200 Subject: [PATCH 5/6] format --- test/testsuppressions.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/testsuppressions.cpp b/test/testsuppressions.cpp index 46daff88b9a..deaa3e5d7d7 100644 --- a/test/testsuppressions.cpp +++ b/test/testsuppressions.cpp @@ -1823,7 +1823,7 @@ class TestSuppressions : public TestFixture { "}\n", "" - ); + ); testXmlSuppressions( "\n" "\n" @@ -1840,7 +1840,7 @@ class TestSuppressions : public TestFixture { "}\n", "[test.c:4:12]: (error) Uninitialized variable: x [uninitvar]\n" - ); + ); } void addSuppressionDuplicate() const { From 6dd3d4b942303046e8bdfff5e15fd66b93d6ce77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Thu, 23 Jul 2026 16:32:36 +0200 Subject: [PATCH 6/6] fix warnings --- test/testsuppressions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testsuppressions.cpp b/test/testsuppressions.cpp index deaa3e5d7d7..18fce1f1eb2 100644 --- a/test/testsuppressions.cpp +++ b/test/testsuppressions.cpp @@ -1785,7 +1785,7 @@ class TestSuppressions : public TestFixture { int thisline, const std::string &xml, const std::string &code, - const std::string expected) + const std::string &expected) { const char *xmlpath = "testsupressions.xml"; const char *sourcepath = "test.c";