Skip to content

Commit 9444fe1

Browse files
committed
suprr [skip ci]
1 parent 0142689 commit 9444fe1

File tree

6 files changed

+35
-12
lines changed

6 files changed

+35
-12
lines changed

gui/mainwindow.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,9 +1022,7 @@ QPair<bool,Settings> MainWindow::getCppcheckSettings()
10221022
tryLoadLibrary(&result.library, filename);
10231023
}
10241024

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

10291027
// Only check the given -D configuration
10301028
if (!defines.isEmpty())

lib/cppcheck.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,11 @@ unsigned int CppCheck::check(const FileSettings &fs)
601601
return returnValue;
602602
}
603603
const unsigned int returnValue = temp.checkFile(Path::simplifyPath(fs.filename), fs.cfg);
604-
mSettings.supprs.nomsg.addSuppressions(temp.mSettings.supprs.nomsg.getSuppressions());
604+
for (const auto& suppr : temp.mSettings.supprs.nomsg.getSuppressions())
605+
{
606+
const bool res = mSettings.supprs.nomsg.updateSuppressionState(suppr);
607+
assert(res);
608+
}
605609
if (mUnusedFunctionsCheck)
606610
mUnusedFunctionsCheck->updateFunctionData(*temp.mUnusedFunctionsCheck);
607611
return returnValue;

lib/preprocessor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ static void addInlineSuppressions(const simplecpp::TokenList &tokens, const Sett
254254
suppr.lineNumber = supprBegin->lineNumber;
255255
suppr.type = SuppressionList::Type::block;
256256
inlineSuppressionsBlockBegin.erase(supprBegin);
257-
suppressions.addSuppression(std::move(suppr));
257+
suppressions.addSuppression(std::move(suppr)); // TODO: check result
258258
throwError = false;
259259
break;
260260
}
@@ -279,10 +279,10 @@ static void addInlineSuppressions(const simplecpp::TokenList &tokens, const Sett
279279
suppr.thisAndNextLine = thisAndNextLine;
280280
suppr.lineNumber = tok->location.line;
281281
suppr.macroName = macroName;
282-
suppressions.addSuppression(std::move(suppr));
282+
suppressions.addSuppression(std::move(suppr)); // TODO: check result
283283
} else if (SuppressionList::Type::file == suppr.type) {
284284
if (onlyComments)
285-
suppressions.addSuppression(std::move(suppr));
285+
suppressions.addSuppression(std::move(suppr)); // TODO: check result
286286
else
287287
bad.emplace_back(suppr.fileName, suppr.lineNumber, "File suppression should be at the top of the file");
288288
}

lib/suppressions.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,7 @@ std::string SuppressionList::addSuppression(SuppressionList::Suppression suppres
250250
auto foundSuppression = std::find_if(mSuppressions.begin(), mSuppressions.end(),
251251
std::bind(&Suppression::isSameParameters, &suppression, std::placeholders::_1));
252252
if (foundSuppression != mSuppressions.end()) {
253-
if (suppression.checked)
254-
foundSuppression->checked = suppression.checked;
255-
if (suppression.matched)
256-
foundSuppression->matched = suppression.matched;
257-
return "";
253+
return "suppression already exists";
258254
}
259255

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

289+
bool SuppressionList::updateSuppressionState(const Suppression& suppression)
290+
{
291+
// Check if suppression is already in list
292+
auto foundSuppression = std::find_if(mSuppressions.begin(), mSuppressions.end(),
293+
std::bind(&Suppression::isSameParameters, &suppression, std::placeholders::_1));
294+
if (foundSuppression != mSuppressions.end()) {
295+
if (suppression.checked)
296+
foundSuppression->checked = suppression.checked;
297+
if (suppression.matched)
298+
foundSuppression->matched = suppression.matched;
299+
return true;
300+
}
301+
302+
return false;
303+
}
304+
293305
void SuppressionList::ErrorMessage::setFileName(std::string s)
294306
{
295307
mFileName = Path::simplifyPath(std::move(s));

lib/suppressions.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,13 @@ class CPPCHECKLIB SuppressionList {
194194
*/
195195
std::string addSuppressions(std::list<Suppression> suppressions);
196196

197+
/**
198+
* @brief Updates the state of the given suppression.
199+
* @param suppression the suppression to update
200+
* @return true if suppression to update was found
201+
*/
202+
bool updateSuppressionState(const Suppression& suppression);
203+
197204
/**
198205
* @brief Returns true if this message should not be shown to the user.
199206
* @param errmsg error message

test/testsuppressions.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,6 +1537,8 @@ class TestSuppressions : public TestFixture {
15371537
ASSERT_EQUALS("unknown element 'eid' in suppressions XML 'suppressparsexml.xml', expected id/fileName/lineNumber/symbolName/hash.", supprList.parseXmlFile(file.path().c_str()));
15381538
}
15391539
}
1540+
1541+
// TODO: test updateSuppressionState
15401542
};
15411543

15421544
REGISTER_TEST(TestSuppressions)

0 commit comments

Comments
 (0)