Skip to content

Commit 19154ed

Browse files
committed
AnalyzerInformation: don't store inline suppressions (Fixes #14974)
There is no situation where a inline suppressed error is needed again. And after loading an analysis we don't know if there were inline suppressions because we don't look at the code again. We have to keep errors that are suppressed otherwise, since command line parameters can change etc., but an inline suppression can not change without changing the file hash which invalidates the cache entry anyways.
1 parent 2d75160 commit 19154ed

3 files changed

Lines changed: 12 additions & 7 deletions

File tree

lib/cppcheck.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,9 @@ class CppCheck::CppCheckLogger : public ErrorLogger
189189
const auto errorMessage = SuppressionList::ErrorMessage::fromErrorMessage(msg, macroNames);
190190

191191
bool suppressed = false;
192+
bool inlineSupressed;
192193

193-
if (mSuppressions.nomsg.isSuppressed(errorMessage, mUseGlobalSuppressions)) {
194+
if (mSuppressions.nomsg.isSuppressed(errorMessage, mUseGlobalSuppressions, &inlineSupressed)) {
194195
// Safety: Report critical errors to ErrorLogger
195196
if (mSettings.safety && ErrorLogger::isCriticalErrorId(msg.id)) {
196197
mExitCode = 1;
@@ -220,7 +221,7 @@ class CppCheck::CppCheckLogger : public ErrorLogger
220221
if (!mSettings.emitDuplicates && !mErrorList.emplace(std::move(errmsg)).second)
221222
return;
222223

223-
if (mAnalyzerInformation)
224+
if (mAnalyzerInformation && !inlineSupressed)
224225
mAnalyzerInformation->reportErr(msg);
225226

226227
if (suppressed)

lib/suppressions.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,10 +472,10 @@ bool SuppressionList::Suppression::isMatch(const SuppressionList::ErrorMessage &
472472
cppcheck::unreachable();
473473
}
474474

475-
bool SuppressionList::isSuppressed(const SuppressionList::ErrorMessage &errmsg, bool global)
476-
{
475+
bool SuppressionList::isSuppressed(const SuppressionList::ErrorMessage &errmsg, bool global, bool *inlineSupressed) {
477476
std::lock_guard<std::mutex> lg(mSuppressionsSync);
478-
477+
if (inlineSupressed)
478+
*inlineSupressed = false;
479479
// TODO: handle unmatchedPolyspaceSuppression?
480480
const bool unmatchedSuppression(errmsg.errorId == "unmatchedSuppression");
481481
bool returnValue = false;
@@ -484,8 +484,11 @@ bool SuppressionList::isSuppressed(const SuppressionList::ErrorMessage &errmsg,
484484
continue;
485485
if (unmatchedSuppression && s.errorId != errmsg.errorId)
486486
continue;
487-
if (s.isMatch(errmsg))
487+
if (s.isMatch(errmsg)) {
488488
returnValue = true;
489+
if (inlineSupressed && s.isInline)
490+
*inlineSupressed = true;
491+
}
489492
}
490493
return returnValue;
491494
}

lib/suppressions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,10 @@ class CPPCHECKLIB SuppressionList {
233233
* @brief Returns true if this message should not be shown to the user.
234234
* @param errmsg error message
235235
* @param global use global suppressions
236+
* @param inlineSupressed is true if there exists an inline suppression for this error
236237
* @return true if this error is suppressed.
237238
*/
238-
bool isSuppressed(const ErrorMessage &errmsg, bool global = true);
239+
bool isSuppressed(const ErrorMessage &errmsg, bool global = true, bool *inlineSupressed = nullptr);
239240

240241
/**
241242
* @brief Returns true if this message is "explicitly" suppressed. The suppression "id" must match textually exactly.

0 commit comments

Comments
 (0)