Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/suppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(text);
else if (std::strcmp(name, "symbolName") == 0)
Expand Down Expand Up @@ -569,7 +569,7 @@ std::list<SuppressionList::Suppression> 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);
}
Expand Down
58 changes: 57 additions & 1 deletion test/cli/other_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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('''
<suppressions>
<suppress>
<id>error3</id>
<fileName>lib/test.c</fileName>
</suppress>
<suppress>
<id>error4</id>
<fileName>lib\\test.c</fileName>
</suppress>
</suppressions>
''')

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