Skip to content

Commit

Permalink
pass Suppressions separately into `CppCheckExecutor::reportSuppress…
Browse files Browse the repository at this point in the history
…ions()` [skip ci]
  • Loading branch information
firewave committed Nov 10, 2023
1 parent c36bafd commit 8210435
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
14 changes: 7 additions & 7 deletions cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ int CppCheckExecutor::check_wrapper(CppCheck& cppcheck)
return check_internal(cppcheck);
}

bool CppCheckExecutor::reportSuppressions(const Settings &settings, bool unusedFunctionCheckEnabled, const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, ErrorLogger& errorLogger) {
const auto& suppressions = settings.nomsg.getSuppressions();
if (std::any_of(suppressions.begin(), suppressions.end(), [](const Suppressions::Suppression& s) {
bool CppCheckExecutor::reportSuppressions(const Settings &settings, const Suppressions& suppressions, bool unusedFunctionCheckEnabled, const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, ErrorLogger& errorLogger) {
const auto& suppr = suppressions.getSuppressions();
if (std::any_of(suppr.begin(), suppr.end(), [](const Suppressions::Suppression& s) {
return s.errorId == "unmatchedSuppression" && s.fileName.empty() && s.lineNumber == Suppressions::Suppression::NO_LINE;
}))
return false;
Expand All @@ -319,15 +319,15 @@ bool CppCheckExecutor::reportSuppressions(const Settings &settings, bool unusedF

for (std::list<std::pair<std::string, std::size_t>>::const_iterator i = files.cbegin(); i != files.cend(); ++i) {
err |= Suppressions::reportUnmatchedSuppressions(
settings.nomsg.getUnmatchedLocalSuppressions(i->first, unusedFunctionCheckEnabled), errorLogger);
suppressions.getUnmatchedLocalSuppressions(i->first, unusedFunctionCheckEnabled), errorLogger);
}

for (std::list<FileSettings>::const_iterator i = fileSettings.cbegin(); i != fileSettings.cend(); ++i) {
err |= Suppressions::reportUnmatchedSuppressions(
settings.nomsg.getUnmatchedLocalSuppressions(i->filename, unusedFunctionCheckEnabled), errorLogger);
suppressions.getUnmatchedLocalSuppressions(i->filename, unusedFunctionCheckEnabled), errorLogger);
}
}
err |= Suppressions::reportUnmatchedSuppressions(settings.nomsg.getUnmatchedGlobalSuppressions(unusedFunctionCheckEnabled), errorLogger);
err |= Suppressions::reportUnmatchedSuppressions(suppressions.getUnmatchedGlobalSuppressions(unusedFunctionCheckEnabled), errorLogger);
return err;
}

Expand Down Expand Up @@ -378,7 +378,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck)
cppcheck.analyseWholeProgram(settings.buildDir, mFiles, mFileSettings);

if (settings.severity.isEnabled(Severity::information) || settings.checkConfiguration) {
const bool err = reportSuppressions(settings, cppcheck.isUnusedFunctionCheckEnabled(), mFiles, mFileSettings, *this);
const bool err = reportSuppressions(settings, settings.nomsg, cppcheck.isUnusedFunctionCheckEnabled(), mFiles, mFileSettings, *this);
if (err && returnValue == 0)
returnValue = settings.exitCode;
}
Expand Down
3 changes: 2 additions & 1 deletion cli/cppcheckexecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
class CppCheck;
class Library;
class Settings;
class Suppressions;

/**
* This class works as an example of how CppCheck can be used in external
Expand Down Expand Up @@ -129,7 +130,7 @@ class CppCheckExecutor : public ErrorLogger {
*/
bool parseFromArgs(Settings &settings, int argc, const char* const argv[]);

static bool reportSuppressions(const Settings &settings, bool unusedFunctionCheckEnabled, const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, ErrorLogger& errorLogger);
static bool reportSuppressions(const Settings &settings, const Suppressions& suppressions, bool unusedFunctionCheckEnabled, const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, ErrorLogger& errorLogger);

/**
* Wrapper around check_internal
Expand Down
6 changes: 3 additions & 3 deletions test/testsuppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class TestSuppressions : public TestFixture {
SingleExecutor executor(cppCheck, filelist, fileSettings, settings, settings.nomsg, *this);
const unsigned int exitCode = executor.check();

CppCheckExecutor::reportSuppressions(settings, false, filelist, fileSettings, *this);
CppCheckExecutor::reportSuppressions(settings, settings.nomsg, false, filelist, fileSettings, *this);

return exitCode;
}
Expand Down Expand Up @@ -303,7 +303,7 @@ class TestSuppressions : public TestFixture {
ThreadExecutor executor(filelist, fileSettings, settings, settings.nomsg, *this, CppCheckExecutor::executeCommand);
const unsigned int exitCode = executor.check();

CppCheckExecutor::reportSuppressions(settings, false, filelist, fileSettings, *this);
CppCheckExecutor::reportSuppressions(settings, settings.nomsg, false, filelist, fileSettings, *this);

return exitCode;
}
Expand Down Expand Up @@ -351,7 +351,7 @@ class TestSuppressions : public TestFixture {
ProcessExecutor executor(filelist, fileSettings, settings, settings.nomsg, *this, CppCheckExecutor::executeCommand);
const unsigned int exitCode = executor.check();

CppCheckExecutor::reportSuppressions(settings, false, filelist, fileSettings, *this);
CppCheckExecutor::reportSuppressions(settings, settings.nomsg, false, filelist, fileSettings, *this);

return exitCode;
}
Expand Down

0 comments on commit 8210435

Please sign in to comment.