Skip to content

Commit

Permalink
suprr [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Mar 11, 2024
1 parent 0142689 commit 9444fe1
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 12 deletions.
4 changes: 1 addition & 3 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1022,9 +1022,7 @@ QPair<bool,Settings> MainWindow::getCppcheckSettings()
tryLoadLibrary(&result.library, filename);
}

for (const SuppressionList::Suppression &suppression : mProjectFile->getSuppressions()) {
result.supprs.nomsg.addSuppression(suppression);
}
result.supprs.nomsg.addSuppressions(mProjectFile->getSuppressions().toStdList()); // TODO: check result

// Only check the given -D configuration
if (!defines.isEmpty())
Expand Down
6 changes: 5 additions & 1 deletion lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,11 @@ unsigned int CppCheck::check(const FileSettings &fs)
return returnValue;
}
const unsigned int returnValue = temp.checkFile(Path::simplifyPath(fs.filename), fs.cfg);
mSettings.supprs.nomsg.addSuppressions(temp.mSettings.supprs.nomsg.getSuppressions());
for (const auto& suppr : temp.mSettings.supprs.nomsg.getSuppressions())
{
const bool res = mSettings.supprs.nomsg.updateSuppressionState(suppr);
assert(res);
}
if (mUnusedFunctionsCheck)
mUnusedFunctionsCheck->updateFunctionData(*temp.mUnusedFunctionsCheck);
return returnValue;
Expand Down
6 changes: 3 additions & 3 deletions lib/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ static void addInlineSuppressions(const simplecpp::TokenList &tokens, const Sett
suppr.lineNumber = supprBegin->lineNumber;
suppr.type = SuppressionList::Type::block;
inlineSuppressionsBlockBegin.erase(supprBegin);
suppressions.addSuppression(std::move(suppr));
suppressions.addSuppression(std::move(suppr)); // TODO: check result
throwError = false;
break;
}
Expand All @@ -279,10 +279,10 @@ static void addInlineSuppressions(const simplecpp::TokenList &tokens, const Sett
suppr.thisAndNextLine = thisAndNextLine;
suppr.lineNumber = tok->location.line;
suppr.macroName = macroName;
suppressions.addSuppression(std::move(suppr));
suppressions.addSuppression(std::move(suppr)); // TODO: check result
} else if (SuppressionList::Type::file == suppr.type) {
if (onlyComments)
suppressions.addSuppression(std::move(suppr));
suppressions.addSuppression(std::move(suppr)); // TODO: check result
else
bad.emplace_back(suppr.fileName, suppr.lineNumber, "File suppression should be at the top of the file");
}
Expand Down
22 changes: 17 additions & 5 deletions lib/suppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,7 @@ std::string SuppressionList::addSuppression(SuppressionList::Suppression suppres
auto foundSuppression = std::find_if(mSuppressions.begin(), mSuppressions.end(),
std::bind(&Suppression::isSameParameters, &suppression, std::placeholders::_1));
if (foundSuppression != mSuppressions.end()) {
if (suppression.checked)
foundSuppression->checked = suppression.checked;
if (suppression.matched)
foundSuppression->matched = suppression.matched;
return "";
return "suppression already exists";
}

// Check that errorId is valid..
Expand Down Expand Up @@ -290,6 +286,22 @@ std::string SuppressionList::addSuppressions(std::list<Suppression> suppressions
return "";
}

bool SuppressionList::updateSuppressionState(const Suppression& suppression)
{
// Check if suppression is already in list
auto foundSuppression = std::find_if(mSuppressions.begin(), mSuppressions.end(),
std::bind(&Suppression::isSameParameters, &suppression, std::placeholders::_1));
if (foundSuppression != mSuppressions.end()) {
if (suppression.checked)
foundSuppression->checked = suppression.checked;
if (suppression.matched)
foundSuppression->matched = suppression.matched;
return true;
}

return false;
}

void SuppressionList::ErrorMessage::setFileName(std::string s)
{
mFileName = Path::simplifyPath(std::move(s));
Expand Down
7 changes: 7 additions & 0 deletions lib/suppressions.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@ class CPPCHECKLIB SuppressionList {
*/
std::string addSuppressions(std::list<Suppression> suppressions);

/**
* @brief Updates the state of the given suppression.
* @param suppression the suppression to update
* @return true if suppression to update was found
*/
bool updateSuppressionState(const Suppression& suppression);

/**
* @brief Returns true if this message should not be shown to the user.
* @param errmsg error message
Expand Down
2 changes: 2 additions & 0 deletions test/testsuppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,8 @@ class TestSuppressions : public TestFixture {
ASSERT_EQUALS("unknown element 'eid' in suppressions XML 'suppressparsexml.xml', expected id/fileName/lineNumber/symbolName/hash.", supprList.parseXmlFile(file.path().c_str()));
}
}

// TODO: test updateSuppressionState
};

REGISTER_TEST(TestSuppressions)

0 comments on commit 9444fe1

Please sign in to comment.