Skip to content

Commit 9453327

Browse files
committed
suprr
1 parent 68accc6 commit 9453327

File tree

6 files changed

+35
-12
lines changed

6 files changed

+35
-12
lines changed

gui/mainwindow.cpp

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

1024-
for (const Suppressions::Suppression &suppression : mProjectFile->getSuppressions()) {
1025-
result.nomsg.addSuppression(suppression);
1026-
}
1024+
result.nomsg.addSuppressions(mProjectFile->getSuppressions().toStdList()); // TODO: check result
10271025

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

lib/cppcheck.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,11 @@ unsigned int CppCheck::check(const FileSettings &fs)
581581
return temp.check(Path::simplifyPath(fs.filename));
582582
}
583583
const unsigned int returnValue = temp.checkFile(Path::simplifyPath(fs.filename), fs.cfg);
584-
mSettings.nomsg.addSuppressions(temp.mSettings.nomsg.getSuppressions());
584+
for (const auto& suppr : temp.mSettings.nomsg.getSuppressions())
585+
{
586+
const bool res = mSettings.nomsg.updateSuppressionState(suppr);
587+
assert(res);
588+
}
585589
return returnValue;
586590
}
587591

lib/preprocessor.cpp

+3-3
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 = Suppressions::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 (Suppressions::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

+17-5
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,7 @@ std::string Suppressions::addSuppression(Suppressions::Suppression suppression)
249249
auto foundSuppression = std::find_if(mSuppressions.begin(), mSuppressions.end(),
250250
std::bind(&Suppression::isSameParameters, &suppression, std::placeholders::_1));
251251
if (foundSuppression != mSuppressions.end()) {
252-
if (suppression.checked)
253-
foundSuppression->checked = suppression.checked;
254-
if (suppression.matched)
255-
foundSuppression->matched = suppression.matched;
256-
return "";
252+
return "suppression already exists";
257253
}
258254

259255
// Check that errorId is valid..
@@ -289,6 +285,22 @@ std::string Suppressions::addSuppressions(std::list<Suppression> suppressions)
289285
return "";
290286
}
291287

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

lib/suppressions.h

+7
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,13 @@ class CPPCHECKLIB Suppressions {
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

+2
Original file line numberDiff line numberDiff line change
@@ -1467,6 +1467,8 @@ class TestSuppressions : public TestFixture {
14671467
ASSERT_EQUALS(true, Suppressions::reportUnmatchedSuppressions(suppressions, *this));
14681468
ASSERT_EQUALS("[a.c:10]: (information) Unmatched suppression: abc\n", errout.str());
14691469
}
1470+
1471+
// TODO: test updateSuppressionState
14701472
};
14711473

14721474
REGISTER_TEST(TestSuppressions)

0 commit comments

Comments
 (0)