diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index 162de168cb6..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) @@ -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 95fd81871a5..3cfe9149725 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -3797,4 +3797,60 @@ 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): # #14248 / #14249 + 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) + ] + + lib_file = 'lib' + os.path.sep + 'test.c' + + ret, stdout, stderr = cppcheck(args) + assert stdout == '' + assert stderr.splitlines() == [ + 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