Skip to content

Commit d6f1153

Browse files
committed
prefer inline suppressions in selfchecks
other_test.py: adjusted `test_unmatched_file` for Windows fixed #14249 - XML suppression parsing did not simplify the file name fixed #14248 - suppressions with subpath not reported as unmatched other_test.py: added test for reporting unmatched suppressions with subpath
1 parent 4cb4c02 commit d6f1153

File tree

5 files changed

+64
-21
lines changed

5 files changed

+64
-21
lines changed

.selfcheck_suppressions

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,6 @@ missingIncludeSystem
22
# should not be reported - see #13387
33
checkersReport
44

5-
# temporary suppressions - fix the warnings!
6-
simplifyUsing:lib/valueptr.h
7-
naming-privateMemberVariable:gui/test/cppchecklibrarydata/testcppchecklibrarydata.h
8-
bitwiseOnBoolean:lib/library.cpp
9-
templateInstantiation:lib/checkunusedfunctions.cpp
10-
templateInstantiation:lib/errorlogger.cpp
11-
templateInstantiation:lib/liobrary.cpp
12-
shadowFunction:lib/checkbufferoverrun.cpp
13-
shadowFunction:lib/checkclass.cpp
14-
shadowFunction:lib/checknullpointer.cpp
15-
shadowFunction:lib/cppcheck.cpp
16-
shadowFunction:lib/fwdanalysis.cpp
17-
shadowFunction:lib/library.cpp
18-
shadowFunction:lib/symboldatabase.cpp
19-
shadowFunction:lib/templatesimplifier.cpp
20-
shadowFunction:lib/token.cpp
21-
shadowFunction:tools/triage/mainwindow.cpp
22-
235
# warnings in Qt generated code we cannot fix
246
funcArgNamesDifferent:*/moc_checkthread.cpp
257
funcArgNamesDifferent:*/moc_codeeditstylecontrols.cpp

gui/test/cppchecklibrarydata/testcppchecklibrarydata.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,13 @@ private slots:
4848
static void loadCfgFile(const QString &filename, CppcheckLibraryData &data, QString &res, bool removeFile = false);
4949
static void saveCfgFile(const QString &filename, CppcheckLibraryData &data);
5050

51+
// cppcheck-suppress naming-privateMemberVariable - TODO: fix this
5152
CppcheckLibraryData libraryData;
53+
// cppcheck-suppress naming-privateMemberVariable - TODO: fix this
5254
CppcheckLibraryData fileLibraryData;
55+
// cppcheck-suppress naming-privateMemberVariable - TODO: fix this
5356
QString result;
5457

58+
// cppcheck-suppress naming-privateMemberVariable - TODO: fix this
5559
static const QString TempCfgFile;
5660
};

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)
@@ -549,7 +549,7 @@ std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedLocalSuppre
549549
continue;
550550
if (s.errorId == ID_CHECKERSREPORT)
551551
continue;
552-
if (!s.isLocal() || s.fileName != file.spath())
552+
if (!s.isLocal() || !PathMatch::match(s.fileName, file.spath()))
553553
continue;
554554
result.push_back(s);
555555
}

lib/valueptr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class CPPCHECKLIB ValuePtr {
3737
public:
3838
using pointer = T*;
3939
using element_type = T;
40+
// cppcheck-suppress simplifyUsing - TODO: fix this
4041
using cloner_type = decltype(&cloner<T>::apply);
4142

4243
ValuePtr() : mPtr(nullptr), mClone() {}

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)