Skip to content

Commit ca87cc1

Browse files
authored
fixed #14248/#14249 - suppressions with subpath were not reported as unmatched (danmar#7940)
1 parent f3d9a37 commit ca87cc1

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

lib/suppressions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ std::string SuppressionList::parseXmlFile(const char *filename)
129129
if (std::strcmp(name, "id") == 0)
130130
s.errorId = text;
131131
else if (std::strcmp(name, "fileName") == 0)
132-
s.fileName = text;
132+
s.fileName = Path::simplifyPath(text);
133133
else if (std::strcmp(name, "lineNumber") == 0)
134134
s.lineNumber = strToInt<int>(text);
135135
else if (std::strcmp(name, "symbolName") == 0)
@@ -569,7 +569,7 @@ std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedLocalSuppre
569569
continue;
570570
if (s.errorId == ID_CHECKERSREPORT)
571571
continue;
572-
if (!s.isLocal() || s.fileName != file.spath())
572+
if (!s.isLocal() || !PathMatch::match(s.fileName, file.spath()))
573573
continue;
574574
result.push_back(s);
575575
}

test/cli/other_test.py

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3797,4 +3797,60 @@ def test_premium_disabled_unmatched(tmp_path): #13663
37973797
'nofile:0:0: information: Unmatched suppression: uninitvar [unmatchedSuppression]'
37983798
]
37993799
assert stdout == ''
3800-
assert ret == 0, stdout
3800+
assert ret == 0, stdout
3801+
3802+
3803+
def test_unmatched_file(tmp_path): # #14248 / #14249
3804+
lib_path = tmp_path / 'lib'
3805+
os.makedirs(lib_path)
3806+
3807+
test_file = lib_path / 'test.c'
3808+
with open(test_file, "w"):
3809+
pass
3810+
3811+
suppr_txt = tmp_path / 'suppr.txt'
3812+
with open(suppr_txt, "w") as f:
3813+
f.write('''
3814+
error:lib/test.c
3815+
error2:lib\\test.c
3816+
''')
3817+
3818+
suppr_xml = tmp_path / 'suppr.xml'
3819+
with open(suppr_xml, "w") as f:
3820+
f.write('''
3821+
<suppressions>
3822+
<suppress>
3823+
<id>error3</id>
3824+
<fileName>lib/test.c</fileName>
3825+
</suppress>
3826+
<suppress>
3827+
<id>error4</id>
3828+
<fileName>lib\\test.c</fileName>
3829+
</suppress>
3830+
</suppressions>
3831+
''')
3832+
3833+
args = [
3834+
'-q',
3835+
'--template=simple',
3836+
'--enable=information',
3837+
f'--suppressions-list={suppr_txt}',
3838+
f'--suppress-xml={suppr_xml}',
3839+
'--suppress=error5:lib/test.c',
3840+
'--suppress=error6:lib\\test.c',
3841+
str(test_file)
3842+
]
3843+
3844+
lib_file = 'lib' + os.path.sep + 'test.c'
3845+
3846+
ret, stdout, stderr = cppcheck(args)
3847+
assert stdout == ''
3848+
assert stderr.splitlines() == [
3849+
f'{lib_file}:-1:0: information: Unmatched suppression: error [unmatchedSuppression]',
3850+
f'{lib_file}:-1:0: information: Unmatched suppression: error2 [unmatchedSuppression]',
3851+
f'{lib_file}:-1:0: information: Unmatched suppression: error3 [unmatchedSuppression]',
3852+
f'{lib_file}:-1:0: information: Unmatched suppression: error4 [unmatchedSuppression]',
3853+
f'{lib_file}:-1:0: information: Unmatched suppression: error5 [unmatchedSuppression]',
3854+
f'{lib_file}:-1:0: information: Unmatched suppression: error6 [unmatchedSuppression]'
3855+
]
3856+
assert ret == 0, stdout

0 commit comments

Comments
 (0)