From 2c0b444632731def4c1408b9fc2c3d3be9b9873d Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 26 Feb 2026 02:41:41 +0100 Subject: [PATCH] fixed #14585 - store all errors in `AnalyzerInfo` even if suppressed --- lib/cppcheck.cpp | 7 ++++++- test/cli/other_test.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 1154d55bd9f..5023a5e258e 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -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)) { @@ -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 @@ -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; } diff --git a/test/cli/other_test.py b/test/cli/other_test.py index ce4089c9ac4..a4e7fc2964d 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -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)