Skip to content

Commit 217c3b3

Browse files
committed
fixed #14585 - store all errors in AnalyzerInfo even if suppressed
1 parent 45e0eb0 commit 217c3b3

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

lib/cppcheck.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ class CppCheck::CppCheckLogger : public ErrorLogger
177177
// TODO: only convert if necessary
178178
const auto errorMessage = SuppressionList::ErrorMessage::fromErrorMessage(msg, macroNames);
179179

180+
bool suppressed = false;
181+
180182
if (mSuppressions.nomsg.isSuppressed(errorMessage, mUseGlobalSuppressions)) {
181183
// Safety: Report critical errors to ErrorLogger
182184
if (mSettings.safety && ErrorLogger::isCriticalErrorId(msg.id)) {
@@ -193,7 +195,7 @@ class CppCheck::CppCheckLogger : public ErrorLogger
193195
mErrorLogger.reportErr(msg);
194196
}
195197
}
196-
return;
198+
suppressed = true;
197199
}
198200

199201
// TODO: there should be no need for the verbose and default messages here
@@ -210,6 +212,9 @@ class CppCheck::CppCheckLogger : public ErrorLogger
210212
if (mAnalyzerInformation)
211213
mAnalyzerInformation->reportErr(msg);
212214

215+
if (suppressed)
216+
return;
217+
213218
if (!mSuppressions.nofail.isSuppressed(errorMessage) && !mSuppressions.nomsg.isSuppressed(errorMessage)) {
214219
mExitCode = 1;
215220
}

test/cli/other_test.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3374,6 +3374,42 @@ def test_suppress_unmatched_wildcard(tmp_path): # #13660
33743374
]
33753375

33763376

3377+
def test_suppress_unmatched_wildcard_cached(tmp_path): # #14585
3378+
test_file = tmp_path / 'test.c'
3379+
with open(test_file, 'wt') as f:
3380+
f.write(
3381+
"""void f()
3382+
{
3383+
(void)(*((int*)0));
3384+
}
3385+
""")
3386+
3387+
build_dir = tmp_path / 'b1'
3388+
os.makedirs(build_dir)
3389+
3390+
# need to run in the temporary folder because the path of the suppression has to match
3391+
args = [
3392+
'-q',
3393+
'--template=simple',
3394+
'--enable=information',
3395+
'--cppcheck-build-dir={}'.format(build_dir),
3396+
'--suppress=nullPointer:test*.c'
3397+
'test.c'
3398+
]
3399+
3400+
stderr_exp = []
3401+
3402+
exitcode, stdout, stderr = cppcheck(args, cwd=tmp_path)
3403+
assert exitcode == 0, stdout
3404+
assert stdout.splitlines() == []
3405+
assert stderr.splitlines() == stderr_exp
3406+
3407+
exitcode, stdout, stderr = cppcheck(args, cwd=tmp_path)
3408+
assert exitcode == 0, stdout
3409+
assert stdout.splitlines() == []
3410+
assert stderr.splitlines() == stderr_exp
3411+
3412+
33773413
def test_suppress_unmatched_wildcard_unchecked(tmp_path):
33783414
# make sure that unmatched wildcards suppressions are reported if files matching the expressions were processesd
33793415
# but isSuppressed() has never been called (i.e. no findings in file at all)

0 commit comments

Comments
 (0)