Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
214 changes: 107 additions & 107 deletions Makefile

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a

mSettings.checkAllConfigurations = false; // Can be overridden with --max-configs or --force
std::string projectFile = argv[i]+10;
ImportProject::Type projType = project.import(projectFile, &mSettings);
ImportProject::Type projType = project.import(projectFile, &mSettings, &mSuppressions);
project.projectType = projType;
if (projType == ImportProject::Type::CPPCHECK_GUI) {
for (const std::string &lib : project.guiProject.libraries)
Expand All @@ -1164,7 +1164,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
if (!projectFileGui.empty()) {
// read underlying project
projectFile = projectFileGui;
projType = project.import(projectFileGui, &mSettings);
projType = project.import(projectFileGui, &mSettings, &mSuppressions);
}
}
if (projType == ImportProject::Type::VS_SLN || projType == ImportProject::Type::VS_VCXPROJ) {
Expand Down Expand Up @@ -1993,7 +1993,7 @@ std::string CmdLineParser::getVersion() const {

bool CmdLineParser::isCppcheckPremium() const {
if (mSettings.cppcheckCfgProductName.empty())
Settings::loadCppcheckCfg(mSettings, mSettings.supprs, mSettings.debuglookup || mSettings.debuglookupConfig);
Settings::loadCppcheckCfg(mSettings, mSuppressions, mSettings.debuglookup || mSettings.debuglookupConfig);
return startsWith(mSettings.cppcheckCfgProductName, "Cppcheck Premium");
}

Expand Down
34 changes: 17 additions & 17 deletions cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ namespace {
/**
* @brief Write the checkers report
*/
void writeCheckersReport();
void writeCheckersReport(const Suppressions& supprs);

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

/**
* Pointer to current settings; set while check() is running for reportError().
* Reference to current settings; set while check() is running for reportError().
*/
const Settings& mSettings;

Expand Down Expand Up @@ -356,7 +356,8 @@ int CppCheckExecutor::check(int argc, const char* const argv[])
{
Settings settings;
CmdLineLoggerStd logger;
CmdLineParser parser(logger, settings, settings.supprs);
Suppressions supprs;
CmdLineParser parser(logger, settings, supprs);
if (!parser.fillSettingsFromArgs(argc, argv)) {
return EXIT_FAILURE;
}
Expand All @@ -371,22 +372,22 @@ int CppCheckExecutor::check(int argc, const char* const argv[])

settings.setMisraRuleTexts(executeCommand);

const int ret = check_wrapper(settings);
const int ret = check_wrapper(settings, supprs);

return ret;
}

int CppCheckExecutor::check_wrapper(const Settings& settings)
int CppCheckExecutor::check_wrapper(const Settings& settings, Suppressions& supprs)
{
#ifdef USE_WINDOWS_SEH
if (settings.exceptionHandling) {
CALL_WITH_SEH_WRAPPER(check_internal(settings));
CALL_WITH_SEH_WRAPPER(check_internal(settings, supprs));
}
#elif defined(USE_UNIX_SIGNAL_HANDLING)
if (settings.exceptionHandling)
register_signal_handler(settings.exceptionOutput);
#endif
return check_internal(settings);
return check_internal(settings, supprs);
}

bool CppCheckExecutor::reportSuppressions(const Settings &settings, const SuppressionList& suppressions, bool unusedFunctionCheckEnabled, const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, ErrorLogger& errorLogger) {
Expand Down Expand Up @@ -418,7 +419,7 @@ bool CppCheckExecutor::reportSuppressions(const Settings &settings, const Suppre
/*
* That is a method which gets called from check_wrapper
* */
int CppCheckExecutor::check_internal(const Settings& settings) const
int CppCheckExecutor::check_internal(const Settings& settings, Suppressions& supprs) const
Comment thread
danmar marked this conversation as resolved.
{
StdLogger stdLogger(settings);

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

CppCheck cppcheck(stdLogger, true, executeCommand);
CppCheck cppcheck(supprs, stdLogger, true, executeCommand);
cppcheck.settings() = settings; // this is a copy
auto& suppressions = cppcheck.settings().supprs.nomsg;

unsigned int returnValue = 0;
if (settings.useSingleJob()) {
// Single process
SingleExecutor executor(cppcheck, mFiles, mFileSettings, settings, suppressions, stdLogger);
SingleExecutor executor(cppcheck, mFiles, mFileSettings, settings, supprs, stdLogger);
returnValue = executor.check();
} else {
#if defined(HAS_THREADING_MODEL_THREAD)
if (settings.executor == Settings::ExecutorType::Thread) {
ThreadExecutor executor(mFiles, mFileSettings, settings, suppressions, stdLogger, CppCheckExecutor::executeCommand);
ThreadExecutor executor(mFiles, mFileSettings, settings, supprs, stdLogger, CppCheckExecutor::executeCommand);
returnValue = executor.check();
}
#endif
#if defined(HAS_THREADING_MODEL_FORK)
if (settings.executor == Settings::ExecutorType::Process) {
ProcessExecutor executor(mFiles, mFileSettings, settings, suppressions, stdLogger, CppCheckExecutor::executeCommand);
ProcessExecutor executor(mFiles, mFileSettings, settings, supprs, stdLogger, CppCheckExecutor::executeCommand);
returnValue = executor.check();
}
#endif
Expand All @@ -466,7 +466,7 @@ int CppCheckExecutor::check_internal(const Settings& settings) const
returnValue |= cppcheck.analyseWholeProgram(settings.buildDir, mFiles, mFileSettings, stdLogger.getCtuInfo());

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

stdLogger.writeCheckersReport();
stdLogger.writeCheckersReport(supprs);

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

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

CheckersReport checkersReport(mSettings, mActiveCheckers);

const auto& suppressions = mSettings.supprs.nomsg.getSuppressions();
const auto& suppressions = supprs.nomsg.getSuppressions();
const bool summarySuppressed = std::any_of(suppressions.cbegin(), suppressions.cend(), [](const SuppressionList::Suppression& s) {
return s.errorId == "checkersReport";
});
Expand Down
7 changes: 5 additions & 2 deletions cli/cppcheckexecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
class Settings;
class ErrorLogger;
class SuppressionList;
struct Suppressions;

/**
* This class works as an example of how CppCheck can be used in external
Expand Down Expand Up @@ -76,20 +77,22 @@ class CppCheckExecutor {
* - installs optional platform dependent signal handling
*
* @param settings the settings
* @param supprs the suppressions
**/
int check_wrapper(const Settings& settings);
int check_wrapper(const Settings& settings, Suppressions& supprs);

/**
* Starts the checking.
*
* @param settings the settings
* @param supprs the suppressions
* @return EXIT_FAILURE if arguments are invalid or no input files
* were found.
* If errors are found and --error-exitcode is used,
* given value is returned instead of default 0.
* If no errors are found, 0 is returned.
*/
int check_internal(const Settings& settings) const;
int check_internal(const Settings& settings, Suppressions& supprs) const;

/**
* Filename associated with size of file
Expand Down
4 changes: 2 additions & 2 deletions cli/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

struct FileSettings;

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

if (!mSuppressions.isSuppressed(msg, {}))
if (!mSuppressions.nomsg.isSuppressed(msg, {}))
{
// TODO: there should be no need for verbose and default messages here
std::string errmsg = msg.toString(mSettings.verbose);
Expand Down
6 changes: 3 additions & 3 deletions cli/executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
class Settings;
class ErrorLogger;
class ErrorMessage;
class SuppressionList;
struct Suppressions;
struct FileSettings;
class FileWithDetails;

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

Executor(const Executor &) = delete;
Expand Down Expand Up @@ -70,7 +70,7 @@ class Executor {
const std::list<FileWithDetails> &mFiles;
const std::list<FileSettings>& mFileSettings;
const Settings &mSettings;
SuppressionList &mSuppressions;
Suppressions &mSuppressions;
ErrorLogger &mErrorLogger;

private:
Expand Down
6 changes: 3 additions & 3 deletions cli/processexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ enum class Color : std::uint8_t;
using std::memset;


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

PipeWriter pipewriter(pipes[1]);
CppCheck fileChecker(pipewriter, false, mExecuteCommand);
CppCheck fileChecker(mSuppressions, pipewriter, false, mExecuteCommand);
fileChecker.settings() = mSettings;
unsigned int resultOfCheck = 0;

Expand Down Expand Up @@ -409,7 +409,7 @@ void ProcessExecutor::reportInternalChildErr(const std::string &childname, const
"cppcheckError",
Certainty::normal);

if (!mSuppressions.isSuppressed(errmsg, {}))
if (!mSuppressions.nomsg.isSuppressed(errmsg, {}))
mErrorLogger.reportErr(errmsg);
}

Expand Down
4 changes: 2 additions & 2 deletions cli/processexecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

class Settings;
class ErrorLogger;
class SuppressionList;
struct Suppressions;
struct FileSettings;
class FileWithDetails;

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

Expand Down
2 changes: 1 addition & 1 deletion cli/singleexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

class ErrorLogger;

SingleExecutor::SingleExecutor(CppCheck &cppcheck, const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, SuppressionList &suppressions, ErrorLogger &errorLogger)
SingleExecutor::SingleExecutor(CppCheck &cppcheck, const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger)
: Executor(files, fileSettings, settings, suppressions, errorLogger)
, mCppcheck(cppcheck)
{
Expand Down
4 changes: 2 additions & 2 deletions cli/singleexecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
class ErrorLogger;
class Settings;
class CppCheck;
class SuppressionList;
struct Suppressions;
struct FileSettings;
class FileWithDetails;

class SingleExecutor : public Executor
{
public:
SingleExecutor(CppCheck &cppcheck, const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, SuppressionList &suppressions, ErrorLogger &errorLogger);
SingleExecutor(CppCheck &cppcheck, const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger);
SingleExecutor(const SingleExecutor &) = delete;
SingleExecutor& operator=(const SingleExecutor &) = delete;

Expand Down
11 changes: 6 additions & 5 deletions cli/threadexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include <utility>
#include <vector>

ThreadExecutor::ThreadExecutor(const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, SuppressionList &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand)
ThreadExecutor::ThreadExecutor(const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand)
: Executor(files, fileSettings, settings, suppressions, errorLogger)
, mExecuteCommand(std::move(executeCommand))
{
Expand Down Expand Up @@ -79,8 +79,8 @@ class SyncLogForwarder : public ErrorLogger
class ThreadData
{
public:
ThreadData(ThreadExecutor &threadExecutor, ErrorLogger &errorLogger, const Settings &settings, const std::list<FileWithDetails> &files, const std::list<FileSettings> &fileSettings, CppCheck::ExecuteCmdFn executeCommand)
: mFiles(files), mFileSettings(fileSettings), mSettings(settings), mExecuteCommand(std::move(executeCommand)), logForwarder(threadExecutor, errorLogger)
ThreadData(ThreadExecutor &threadExecutor, ErrorLogger &errorLogger, const Settings &settings, Suppressions& supprs, const std::list<FileWithDetails> &files, const std::list<FileSettings> &fileSettings, CppCheck::ExecuteCmdFn executeCommand)
: mFiles(files), mFileSettings(fileSettings), mSettings(settings), mSuppressions(supprs), mExecuteCommand(std::move(executeCommand)), logForwarder(threadExecutor, errorLogger)
{
mItNextFile = mFiles.begin();
mItNextFileSettings = mFileSettings.begin();
Expand Down Expand Up @@ -112,7 +112,7 @@ class ThreadData
}

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

unsigned int result;
Expand Down Expand Up @@ -150,6 +150,7 @@ class ThreadData

std::mutex mFileSync;
const Settings &mSettings;
Suppressions &mSuppressions;
CppCheck::ExecuteCmdFn mExecuteCommand;

public:
Expand Down Expand Up @@ -178,7 +179,7 @@ unsigned int ThreadExecutor::check()
std::vector<std::future<unsigned int>> threadFutures;
threadFutures.reserve(mSettings.jobs);

ThreadData data(*this, mErrorLogger, mSettings, mFiles, mFileSettings, mExecuteCommand);
ThreadData data(*this, mErrorLogger, mSettings, mSuppressions, mFiles, mFileSettings, mExecuteCommand);

for (unsigned int i = 0; i < mSettings.jobs; ++i) {
try {
Expand Down
4 changes: 2 additions & 2 deletions cli/threadexecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

class Settings;
class ErrorLogger;
class SuppressionList;
struct Suppressions;
struct FileSettings;
class FileWithDetails;

Expand All @@ -41,7 +41,7 @@ class ThreadExecutor : public Executor {
friend class SyncLogForwarder;

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

Expand Down
4 changes: 3 additions & 1 deletion democlient/democlient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "errortypes.h"
#include "filesettings.h"
#include "settings.h"
#include "suppressions.h"
#include "version.h"

#include <algorithm>
Expand Down Expand Up @@ -56,13 +57,14 @@ static FILE *logfile = nullptr;
class CppcheckExecutor : public ErrorLogger {
private:
const std::time_t stoptime;
Suppressions supprs;
CppCheck cppcheck;

public:
CppcheckExecutor()
: ErrorLogger()
, stoptime(std::time(nullptr)+2U)
, cppcheck(*this, false, nullptr) {
, cppcheck(supprs, *this, false, nullptr) {
cppcheck.settings().addEnabled("all");
cppcheck.settings().certainty.enable(Certainty::inconclusive);
}
Expand Down
Loading