Skip to content
Open
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
7 changes: 6 additions & 1 deletion lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ class CppCheck::CppCheckLogger : public ErrorLogger
// TODO: only convert if necessary
const auto errorMessage = SuppressionList::ErrorMessage::fromErrorMessage(msg, macroNames);

bool suppressed = false;

if (mSuppressions.nomsg.isSuppressed(errorMessage, mUseGlobalSuppressions)) {
// Safety: Report critical errors to ErrorLogger
if (mSettings.safety && ErrorLogger::isCriticalErrorId(msg.id)) {
Expand All @@ -193,7 +195,7 @@ class CppCheck::CppCheckLogger : public ErrorLogger
mErrorLogger.reportErr(msg);
}
}
return;
suppressed = true;
}

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

if (suppressed)
return;

if (!mSuppressions.nofail.isSuppressed(errorMessage) && !mSuppressions.nomsg.isSuppressed(errorMessage)) {
mExitCode = 1;
}
Expand Down
36 changes: 36 additions & 0 deletions test/cli/other_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3374,6 +3374,42 @@ def test_suppress_unmatched_wildcard(tmp_path): # #13660
]


def test_suppress_unmatched_wildcard_cached(tmp_path): # #14585
test_file = tmp_path / 'test.c'
with open(test_file, 'wt') as f:
f.write(
"""void f()
{
(void)(*((int*)0));
}
""")

build_dir = tmp_path / 'b1'
os.makedirs(build_dir)

# need to run in the temporary folder because the path of the suppression has to match
args = [
'-q',
'--template=simple',
'--enable=information',
'--cppcheck-build-dir={}'.format(build_dir),
'--suppress=nullPointer:test*.c',
'test.c'
]

stderr_exp = []

exitcode, stdout, stderr = cppcheck(args, cwd=tmp_path)
assert exitcode == 0, stdout
assert stdout.splitlines() == []
assert stderr.splitlines() == stderr_exp

exitcode, stdout, stderr = cppcheck(args, cwd=tmp_path)
assert exitcode == 0, stdout
assert stdout.splitlines() == []
assert stderr.splitlines() == stderr_exp


def test_suppress_unmatched_wildcard_unchecked(tmp_path):
# make sure that unmatched wildcards suppressions are reported if files matching the expressions were processesd
# but isSuppressed() has never been called (i.e. no findings in file at all)
Expand Down
Loading