Skip to content

Commit fe6a2e3

Browse files
authored
split suppressions from settings (#7284)
1 parent abe99cb commit fe6a2e3

40 files changed

+548
-441
lines changed

Makefile

Lines changed: 107 additions & 107 deletions
Large diffs are not rendered by default.

cli/cmdlineparser.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
11421142

11431143
mSettings.checkAllConfigurations = false; // Can be overridden with --max-configs or --force
11441144
std::string projectFile = argv[i]+10;
1145-
ImportProject::Type projType = project.import(projectFile, &mSettings);
1145+
ImportProject::Type projType = project.import(projectFile, &mSettings, &mSuppressions);
11461146
project.projectType = projType;
11471147
if (projType == ImportProject::Type::CPPCHECK_GUI) {
11481148
for (const std::string &lib : project.guiProject.libraries)
@@ -1167,7 +1167,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
11671167
if (!projectFileGui.empty()) {
11681168
// read underlying project
11691169
projectFile = projectFileGui;
1170-
projType = project.import(projectFileGui, &mSettings);
1170+
projType = project.import(projectFileGui, &mSettings, &mSuppressions);
11711171
}
11721172
}
11731173
if (projType == ImportProject::Type::VS_SLN || projType == ImportProject::Type::VS_VCXPROJ) {
@@ -1997,7 +1997,7 @@ std::string CmdLineParser::getVersion() const {
19971997

19981998
bool CmdLineParser::isCppcheckPremium() const {
19991999
if (mSettings.cppcheckCfgProductName.empty())
2000-
Settings::loadCppcheckCfg(mSettings, mSettings.supprs, mSettings.debuglookup || mSettings.debuglookupConfig);
2000+
Settings::loadCppcheckCfg(mSettings, mSuppressions, mSettings.debuglookup || mSettings.debuglookupConfig);
20012001
return startsWith(mSettings.cppcheckCfgProductName, "Cppcheck Premium");
20022002
}
20032003

cli/cppcheckexecutor.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ namespace {
280280
/**
281281
* @brief Write the checkers report
282282
*/
283-
void writeCheckersReport();
283+
void writeCheckersReport(const Suppressions& supprs);
284284

285285
bool hasCriticalErrors() const {
286286
return !mCriticalErrors.empty();
@@ -305,7 +305,7 @@ namespace {
305305
void reportProgress(const std::string &filename, const char stage[], std::size_t value) override;
306306

307307
/**
308-
* Pointer to current settings; set while check() is running for reportError().
308+
* Reference to current settings; set while check() is running for reportError().
309309
*/
310310
const Settings& mSettings;
311311

@@ -356,7 +356,8 @@ int CppCheckExecutor::check(int argc, const char* const argv[])
356356
{
357357
Settings settings;
358358
CmdLineLoggerStd logger;
359-
CmdLineParser parser(logger, settings, settings.supprs);
359+
Suppressions supprs;
360+
CmdLineParser parser(logger, settings, supprs);
360361
if (!parser.fillSettingsFromArgs(argc, argv)) {
361362
return EXIT_FAILURE;
362363
}
@@ -371,22 +372,22 @@ int CppCheckExecutor::check(int argc, const char* const argv[])
371372

372373
settings.setMisraRuleTexts(executeCommand);
373374

374-
const int ret = check_wrapper(settings);
375+
const int ret = check_wrapper(settings, supprs);
375376

376377
return ret;
377378
}
378379

379-
int CppCheckExecutor::check_wrapper(const Settings& settings)
380+
int CppCheckExecutor::check_wrapper(const Settings& settings, Suppressions& supprs)
380381
{
381382
#ifdef USE_WINDOWS_SEH
382383
if (settings.exceptionHandling) {
383-
CALL_WITH_SEH_WRAPPER(check_internal(settings));
384+
CALL_WITH_SEH_WRAPPER(check_internal(settings, supprs));
384385
}
385386
#elif defined(USE_UNIX_SIGNAL_HANDLING)
386387
if (settings.exceptionHandling)
387388
register_signal_handler(settings.exceptionOutput);
388389
#endif
389-
return check_internal(settings);
390+
return check_internal(settings, supprs);
390391
}
391392

392393
bool CppCheckExecutor::reportSuppressions(const Settings &settings, const SuppressionList& suppressions, bool unusedFunctionCheckEnabled, const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, ErrorLogger& errorLogger) {
@@ -418,7 +419,7 @@ bool CppCheckExecutor::reportSuppressions(const Settings &settings, const Suppre
418419
/*
419420
* That is a method which gets called from check_wrapper
420421
* */
421-
int CppCheckExecutor::check_internal(const Settings& settings) const
422+
int CppCheckExecutor::check_internal(const Settings& settings, Suppressions& supprs) const
422423
{
423424
StdLogger stdLogger(settings);
424425

@@ -439,25 +440,24 @@ int CppCheckExecutor::check_internal(const Settings& settings) const
439440
if (!settings.checkersReportFilename.empty())
440441
std::remove(settings.checkersReportFilename.c_str());
441442

442-
CppCheck cppcheck(stdLogger, true, executeCommand);
443+
CppCheck cppcheck(supprs, stdLogger, true, executeCommand);
443444
cppcheck.settings() = settings; // this is a copy
444-
auto& suppressions = cppcheck.settings().supprs.nomsg;
445445

446446
unsigned int returnValue = 0;
447447
if (settings.useSingleJob()) {
448448
// Single process
449-
SingleExecutor executor(cppcheck, mFiles, mFileSettings, settings, suppressions, stdLogger);
449+
SingleExecutor executor(cppcheck, mFiles, mFileSettings, settings, supprs, stdLogger);
450450
returnValue = executor.check();
451451
} else {
452452
#if defined(HAS_THREADING_MODEL_THREAD)
453453
if (settings.executor == Settings::ExecutorType::Thread) {
454-
ThreadExecutor executor(mFiles, mFileSettings, settings, suppressions, stdLogger, CppCheckExecutor::executeCommand);
454+
ThreadExecutor executor(mFiles, mFileSettings, settings, supprs, stdLogger, CppCheckExecutor::executeCommand);
455455
returnValue = executor.check();
456456
}
457457
#endif
458458
#if defined(HAS_THREADING_MODEL_FORK)
459459
if (settings.executor == Settings::ExecutorType::Process) {
460-
ProcessExecutor executor(mFiles, mFileSettings, settings, suppressions, stdLogger, CppCheckExecutor::executeCommand);
460+
ProcessExecutor executor(mFiles, mFileSettings, settings, supprs, stdLogger, CppCheckExecutor::executeCommand);
461461
returnValue = executor.check();
462462
}
463463
#endif
@@ -466,7 +466,7 @@ int CppCheckExecutor::check_internal(const Settings& settings) const
466466
returnValue |= cppcheck.analyseWholeProgram(settings.buildDir, mFiles, mFileSettings, stdLogger.getCtuInfo());
467467

468468
if (settings.severity.isEnabled(Severity::information) || settings.checkConfiguration) {
469-
const bool err = reportSuppressions(settings, suppressions, settings.checks.isEnabled(Checks::unusedFunction), mFiles, mFileSettings, stdLogger);
469+
const bool err = reportSuppressions(settings, supprs.nomsg, settings.checks.isEnabled(Checks::unusedFunction), mFiles, mFileSettings, stdLogger);
470470
if (err && returnValue == 0)
471471
returnValue = settings.exitCode;
472472
}
@@ -475,7 +475,7 @@ int CppCheckExecutor::check_internal(const Settings& settings) const
475475
cppcheck.tooManyConfigsError("",0U);
476476
}
477477

478-
stdLogger.writeCheckersReport();
478+
stdLogger.writeCheckersReport(supprs);
479479

480480
if (settings.outputFormat == Settings::OutputFormat::xml) {
481481
stdLogger.reportErr(ErrorMessage::getXMLFooter(settings.xml_version));
@@ -489,7 +489,7 @@ int CppCheckExecutor::check_internal(const Settings& settings) const
489489
return EXIT_SUCCESS;
490490
}
491491

492-
void StdLogger::writeCheckersReport()
492+
void StdLogger::writeCheckersReport(const Suppressions& supprs)
493493
{
494494
const bool summary = mSettings.safety || mSettings.severity.isEnabled(Severity::information);
495495
const bool xmlReport = mSettings.outputFormat == Settings::OutputFormat::xml && mSettings.xml_version == 3;
@@ -500,7 +500,7 @@ void StdLogger::writeCheckersReport()
500500

501501
CheckersReport checkersReport(mSettings, mActiveCheckers);
502502

503-
const auto& suppressions = mSettings.supprs.nomsg.getSuppressions();
503+
const auto& suppressions = supprs.nomsg.getSuppressions();
504504
const bool summarySuppressed = std::any_of(suppressions.cbegin(), suppressions.cend(), [](const SuppressionList::Suppression& s) {
505505
return s.errorId == "checkersReport";
506506
});

cli/cppcheckexecutor.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
class Settings;
2929
class ErrorLogger;
3030
class SuppressionList;
31+
struct Suppressions;
3132

3233
/**
3334
* This class works as an example of how CppCheck can be used in external
@@ -76,20 +77,22 @@ class CppCheckExecutor {
7677
* - installs optional platform dependent signal handling
7778
*
7879
* @param settings the settings
80+
* @param supprs the suppressions
7981
**/
80-
int check_wrapper(const Settings& settings);
82+
int check_wrapper(const Settings& settings, Suppressions& supprs);
8183

8284
/**
8385
* Starts the checking.
8486
*
8587
* @param settings the settings
88+
* @param supprs the suppressions
8689
* @return EXIT_FAILURE if arguments are invalid or no input files
8790
* were found.
8891
* If errors are found and --error-exitcode is used,
8992
* given value is returned instead of default 0.
9093
* If no errors are found, 0 is returned.
9194
*/
92-
int check_internal(const Settings& settings) const;
95+
int check_internal(const Settings& settings, Suppressions& supprs) const;
9396

9497
/**
9598
* Filename associated with size of file

cli/executor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
struct FileSettings;
3232

33-
Executor::Executor(const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, SuppressionList &suppressions, ErrorLogger &errorLogger)
33+
Executor::Executor(const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger)
3434
: mFiles(files), mFileSettings(fileSettings), mSettings(settings), mSuppressions(suppressions), mErrorLogger(errorLogger)
3535
{
3636
// the two inputs may only be used exclusively
@@ -43,7 +43,7 @@ bool Executor::hasToLog(const ErrorMessage &msg)
4343
if (msg.severity == Severity::internal)
4444
return true;
4545

46-
if (!mSuppressions.isSuppressed(msg, {}))
46+
if (!mSuppressions.nomsg.isSuppressed(msg, {}))
4747
{
4848
// TODO: there should be no need for verbose and default messages here
4949
std::string errmsg = msg.toString(mSettings.verbose);

cli/executor.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
class Settings;
2929
class ErrorLogger;
3030
class ErrorMessage;
31-
class SuppressionList;
31+
struct Suppressions;
3232
struct FileSettings;
3333
class FileWithDetails;
3434

@@ -41,7 +41,7 @@ class FileWithDetails;
4141
*/
4242
class Executor {
4343
public:
44-
Executor(const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, SuppressionList &suppressions, ErrorLogger &errorLogger);
44+
Executor(const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger);
4545
virtual ~Executor() = default;
4646

4747
Executor(const Executor &) = delete;
@@ -70,7 +70,7 @@ class Executor {
7070
const std::list<FileWithDetails> &mFiles;
7171
const std::list<FileSettings>& mFileSettings;
7272
const Settings &mSettings;
73-
SuppressionList &mSuppressions;
73+
Suppressions &mSuppressions;
7474
ErrorLogger &mErrorLogger;
7575

7676
private:

cli/processexecutor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ enum class Color : std::uint8_t;
6868
using std::memset;
6969

7070

71-
ProcessExecutor::ProcessExecutor(const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, SuppressionList &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand)
71+
ProcessExecutor::ProcessExecutor(const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand)
7272
: Executor(files, fileSettings, settings, suppressions, errorLogger)
7373
, mExecuteCommand(std::move(executeCommand))
7474
{
@@ -284,7 +284,7 @@ unsigned int ProcessExecutor::check()
284284
close(pipes[0]);
285285

286286
PipeWriter pipewriter(pipes[1]);
287-
CppCheck fileChecker(pipewriter, false, mExecuteCommand);
287+
CppCheck fileChecker(mSuppressions, pipewriter, false, mExecuteCommand);
288288
fileChecker.settings() = mSettings;
289289
unsigned int resultOfCheck = 0;
290290

@@ -409,7 +409,7 @@ void ProcessExecutor::reportInternalChildErr(const std::string &childname, const
409409
"cppcheckError",
410410
Certainty::normal);
411411

412-
if (!mSuppressions.isSuppressed(errmsg, {}))
412+
if (!mSuppressions.nomsg.isSuppressed(errmsg, {}))
413413
mErrorLogger.reportErr(errmsg);
414414
}
415415

cli/processexecutor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
class Settings;
3030
class ErrorLogger;
31-
class SuppressionList;
31+
struct Suppressions;
3232
struct FileSettings;
3333
class FileWithDetails;
3434

@@ -41,7 +41,7 @@ class FileWithDetails;
4141
*/
4242
class ProcessExecutor : public Executor {
4343
public:
44-
ProcessExecutor(const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, SuppressionList &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand);
44+
ProcessExecutor(const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand);
4545
ProcessExecutor(const ProcessExecutor &) = delete;
4646
ProcessExecutor& operator=(const ProcessExecutor &) = delete;
4747

cli/singleexecutor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
class ErrorLogger;
3232

33-
SingleExecutor::SingleExecutor(CppCheck &cppcheck, const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, SuppressionList &suppressions, ErrorLogger &errorLogger)
33+
SingleExecutor::SingleExecutor(CppCheck &cppcheck, const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger)
3434
: Executor(files, fileSettings, settings, suppressions, errorLogger)
3535
, mCppcheck(cppcheck)
3636
{

cli/singleexecutor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
class ErrorLogger;
2727
class Settings;
2828
class CppCheck;
29-
class SuppressionList;
29+
struct Suppressions;
3030
struct FileSettings;
3131
class FileWithDetails;
3232

3333
class SingleExecutor : public Executor
3434
{
3535
public:
36-
SingleExecutor(CppCheck &cppcheck, const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, SuppressionList &suppressions, ErrorLogger &errorLogger);
36+
SingleExecutor(CppCheck &cppcheck, const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger);
3737
SingleExecutor(const SingleExecutor &) = delete;
3838
SingleExecutor& operator=(const SingleExecutor &) = delete;
3939

cli/threadexecutor.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#include <utility>
3838
#include <vector>
3939

40-
ThreadExecutor::ThreadExecutor(const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, SuppressionList &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand)
40+
ThreadExecutor::ThreadExecutor(const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand)
4141
: Executor(files, fileSettings, settings, suppressions, errorLogger)
4242
, mExecuteCommand(std::move(executeCommand))
4343
{
@@ -79,8 +79,8 @@ class SyncLogForwarder : public ErrorLogger
7979
class ThreadData
8080
{
8181
public:
82-
ThreadData(ThreadExecutor &threadExecutor, ErrorLogger &errorLogger, const Settings &settings, const std::list<FileWithDetails> &files, const std::list<FileSettings> &fileSettings, CppCheck::ExecuteCmdFn executeCommand)
83-
: mFiles(files), mFileSettings(fileSettings), mSettings(settings), mExecuteCommand(std::move(executeCommand)), logForwarder(threadExecutor, errorLogger)
82+
ThreadData(ThreadExecutor &threadExecutor, ErrorLogger &errorLogger, const Settings &settings, Suppressions& supprs, const std::list<FileWithDetails> &files, const std::list<FileSettings> &fileSettings, CppCheck::ExecuteCmdFn executeCommand)
83+
: mFiles(files), mFileSettings(fileSettings), mSettings(settings), mSuppressions(supprs), mExecuteCommand(std::move(executeCommand)), logForwarder(threadExecutor, errorLogger)
8484
{
8585
mItNextFile = mFiles.begin();
8686
mItNextFileSettings = mFileSettings.begin();
@@ -112,7 +112,7 @@ class ThreadData
112112
}
113113

114114
unsigned int check(ErrorLogger &errorLogger, const FileWithDetails *file, const FileSettings *fs) const {
115-
CppCheck fileChecker(errorLogger, false, mExecuteCommand);
115+
CppCheck fileChecker(mSuppressions, errorLogger, false, mExecuteCommand);
116116
fileChecker.settings() = mSettings; // this is a copy
117117

118118
unsigned int result;
@@ -150,6 +150,7 @@ class ThreadData
150150

151151
std::mutex mFileSync;
152152
const Settings &mSettings;
153+
Suppressions &mSuppressions;
153154
CppCheck::ExecuteCmdFn mExecuteCommand;
154155

155156
public:
@@ -178,7 +179,7 @@ unsigned int ThreadExecutor::check()
178179
std::vector<std::future<unsigned int>> threadFutures;
179180
threadFutures.reserve(mSettings.jobs);
180181

181-
ThreadData data(*this, mErrorLogger, mSettings, mFiles, mFileSettings, mExecuteCommand);
182+
ThreadData data(*this, mErrorLogger, mSettings, mSuppressions, mFiles, mFileSettings, mExecuteCommand);
182183

183184
for (unsigned int i = 0; i < mSettings.jobs; ++i) {
184185
try {

cli/threadexecutor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
class Settings;
2828
class ErrorLogger;
29-
class SuppressionList;
29+
struct Suppressions;
3030
struct FileSettings;
3131
class FileWithDetails;
3232

@@ -41,7 +41,7 @@ class ThreadExecutor : public Executor {
4141
friend class SyncLogForwarder;
4242

4343
public:
44-
ThreadExecutor(const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, SuppressionList &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand);
44+
ThreadExecutor(const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand);
4545
ThreadExecutor(const ThreadExecutor &) = delete;
4646
ThreadExecutor& operator=(const ThreadExecutor &) = delete;
4747

democlient/democlient.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "errortypes.h"
2222
#include "filesettings.h"
2323
#include "settings.h"
24+
#include "suppressions.h"
2425
#include "version.h"
2526

2627
#include <algorithm>
@@ -56,13 +57,14 @@ static FILE *logfile = nullptr;
5657
class CppcheckExecutor : public ErrorLogger {
5758
private:
5859
const std::time_t stoptime;
60+
Suppressions supprs;
5961
CppCheck cppcheck;
6062

6163
public:
6264
CppcheckExecutor()
6365
: ErrorLogger()
6466
, stoptime(std::time(nullptr)+2U)
65-
, cppcheck(*this, false, nullptr) {
67+
, cppcheck(supprs, *this, false, nullptr) {
6668
cppcheck.settings().addEnabled("all");
6769
cppcheck.settings().certainty.enable(Certainty::inconclusive);
6870
}

0 commit comments

Comments
 (0)