From 7c36faefc3fe0563e1bb78809b3e76960fdec05f Mon Sep 17 00:00:00 2001 From: firewave Date: Sat, 1 Nov 2025 13:40:50 +0100 Subject: [PATCH 1/4] other_test.py: added test for reporting unmatched suppressions with subpath --- test/cli/other_test.py | 50 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/test/cli/other_test.py b/test/cli/other_test.py index 95fd81871a5..5369cf2660e 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -3797,4 +3797,52 @@ def test_premium_disabled_unmatched(tmp_path): #13663 'nofile:0:0: information: Unmatched suppression: uninitvar [unmatchedSuppression]' ] assert stdout == '' - assert ret == 0, stdout \ No newline at end of file + assert ret == 0, stdout + + +def test_unmatched_file(tmp_path): + lib_path = tmp_path / 'lib' + os.makedirs(lib_path) + + test_file = lib_path / 'test.c' + with open(test_file, "w"): + pass + + suppr_txt = tmp_path / 'suppr.txt' + with open(suppr_txt, "w") as f: + f.write(''' +error:lib/test.c +error2:lib\\test.c +''') + + suppr_xml = tmp_path / 'suppr.xml' + with open(suppr_xml, "w") as f: + f.write(''' + + + error3 + lib/test.c + + + error4 + lib\\test.c + + +''') + + args = [ + '-q', + '--template=simple', + '--enable=information', + f'--suppressions-list={suppr_txt}', + f'--suppress-xml={suppr_xml}', + '--suppress=error5:lib/test.c', + '--suppress=error6:lib\\test.c', + str(test_file) + ] + + ret, stdout, stderr = cppcheck(args) + assert stdout == '' + assert stderr.splitlines() == [ + ] + assert ret == 0, stdout From 7289296488759fd4769a7b23162f93f894d8f67e Mon Sep 17 00:00:00 2001 From: firewave Date: Sat, 1 Nov 2025 13:33:27 +0100 Subject: [PATCH 2/4] fixed #14248 - suppressions with subpath not reported as unmatched --- lib/suppressions.cpp | 2 +- test/cli/other_test.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index 162de168cb6..8f6f89ff05a 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -569,7 +569,7 @@ std::list SuppressionList::getUnmatchedLocalSuppre continue; if (s.errorId == ID_CHECKERSREPORT) continue; - if (!s.isLocal() || s.fileName != file.spath()) + if (!s.isLocal() || !PathMatch::match(s.fileName, file.spath())) continue; result.push_back(s); } diff --git a/test/cli/other_test.py b/test/cli/other_test.py index 5369cf2660e..f8c9e70ba51 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -3800,7 +3800,7 @@ def test_premium_disabled_unmatched(tmp_path): #13663 assert ret == 0, stdout -def test_unmatched_file(tmp_path): +def test_unmatched_file(tmp_path): # #14248 lib_path = tmp_path / 'lib' os.makedirs(lib_path) @@ -3844,5 +3844,10 @@ def test_unmatched_file(tmp_path): ret, stdout, stderr = cppcheck(args) assert stdout == '' assert stderr.splitlines() == [ + 'lib/test.c:-1:0: information: Unmatched suppression: error [unmatchedSuppression]', + 'lib/test.c:-1:0: information: Unmatched suppression: error2 [unmatchedSuppression]', + 'lib/test.c:-1:0: information: Unmatched suppression: error3 [unmatchedSuppression]', + 'lib/test.c:-1:0: information: Unmatched suppression: error5 [unmatchedSuppression]', + 'lib/test.c:-1:0: information: Unmatched suppression: error6 [unmatchedSuppression]' ] assert ret == 0, stdout From c990c8a5878db8dd7ca347ae65578a807d081e89 Mon Sep 17 00:00:00 2001 From: firewave Date: Sat, 1 Nov 2025 13:34:19 +0100 Subject: [PATCH 3/4] fixed #14249 - XML suppression parsing did not simplify the file name --- lib/suppressions.cpp | 2 +- test/cli/other_test.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index 8f6f89ff05a..7724082480d 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -129,7 +129,7 @@ std::string SuppressionList::parseXmlFile(const char *filename) if (std::strcmp(name, "id") == 0) s.errorId = text; else if (std::strcmp(name, "fileName") == 0) - s.fileName = text; + s.fileName = Path::simplifyPath(text); else if (std::strcmp(name, "lineNumber") == 0) s.lineNumber = strToInt(text); else if (std::strcmp(name, "symbolName") == 0) diff --git a/test/cli/other_test.py b/test/cli/other_test.py index f8c9e70ba51..25bf6392128 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -3800,7 +3800,7 @@ def test_premium_disabled_unmatched(tmp_path): #13663 assert ret == 0, stdout -def test_unmatched_file(tmp_path): # #14248 +def test_unmatched_file(tmp_path): # #14248 / #14249 lib_path = tmp_path / 'lib' os.makedirs(lib_path) @@ -3847,6 +3847,7 @@ def test_unmatched_file(tmp_path): # #14248 'lib/test.c:-1:0: information: Unmatched suppression: error [unmatchedSuppression]', 'lib/test.c:-1:0: information: Unmatched suppression: error2 [unmatchedSuppression]', 'lib/test.c:-1:0: information: Unmatched suppression: error3 [unmatchedSuppression]', + 'lib/test.c:-1:0: information: Unmatched suppression: error4 [unmatchedSuppression]', 'lib/test.c:-1:0: information: Unmatched suppression: error5 [unmatchedSuppression]', 'lib/test.c:-1:0: information: Unmatched suppression: error6 [unmatchedSuppression]' ] From dc8df3565d42f0873ba1bc620636f09587abc928 Mon Sep 17 00:00:00 2001 From: firewave Date: Sat, 1 Nov 2025 14:03:05 +0100 Subject: [PATCH 4/4] other_test.py: adjusted `test_unmatched_file` for Windows --- test/cli/other_test.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/cli/other_test.py b/test/cli/other_test.py index 25bf6392128..3cfe9149725 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -3841,14 +3841,16 @@ def test_unmatched_file(tmp_path): # #14248 / #14249 str(test_file) ] + lib_file = 'lib' + os.path.sep + 'test.c' + ret, stdout, stderr = cppcheck(args) assert stdout == '' assert stderr.splitlines() == [ - 'lib/test.c:-1:0: information: Unmatched suppression: error [unmatchedSuppression]', - 'lib/test.c:-1:0: information: Unmatched suppression: error2 [unmatchedSuppression]', - 'lib/test.c:-1:0: information: Unmatched suppression: error3 [unmatchedSuppression]', - 'lib/test.c:-1:0: information: Unmatched suppression: error4 [unmatchedSuppression]', - 'lib/test.c:-1:0: information: Unmatched suppression: error5 [unmatchedSuppression]', - 'lib/test.c:-1:0: information: Unmatched suppression: error6 [unmatchedSuppression]' + f'{lib_file}:-1:0: information: Unmatched suppression: error [unmatchedSuppression]', + f'{lib_file}:-1:0: information: Unmatched suppression: error2 [unmatchedSuppression]', + f'{lib_file}:-1:0: information: Unmatched suppression: error3 [unmatchedSuppression]', + f'{lib_file}:-1:0: information: Unmatched suppression: error4 [unmatchedSuppression]', + f'{lib_file}:-1:0: information: Unmatched suppression: error5 [unmatchedSuppression]', + f'{lib_file}:-1:0: information: Unmatched suppression: error6 [unmatchedSuppression]' ] assert ret == 0, stdout