Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some CppCheck and related usage cleanups #5979

Merged
merged 6 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
CppCheckExecutor: moved CppCheck instance into check_internal()
  • Loading branch information
firewave committed Feb 12, 2024
commit 41553bcacf2f833322f70b18a6a2f719687e4746
25 changes: 12 additions & 13 deletions cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,26 +195,23 @@ int CppCheckExecutor::check(int argc, const char* const argv[])

mStdLogger = new StdLogger(settings);

CppCheck cppCheck(*mStdLogger, true, executeCommand);
cppCheck.settings() = settings; // this is a copy

const int ret = check_wrapper(cppCheck);
const int ret = check_wrapper(settings);

delete mStdLogger;
mStdLogger = nullptr;
return ret;
}

int CppCheckExecutor::check_wrapper(CppCheck& cppcheck)
int CppCheckExecutor::check_wrapper(const Settings& settings)
{
#ifdef USE_WINDOWS_SEH
if (cppcheck.settings().exceptionHandling)
return check_wrapper_seh(*this, &CppCheckExecutor::check_internal, cppcheck);
if (settings.exceptionHandling)
return check_wrapper_seh(*this, &CppCheckExecutor::check_internal, settings);
#elif defined(USE_UNIX_SIGNAL_HANDLING)
if (cppcheck.settings().exceptionHandling)
return check_wrapper_sig(*this, &CppCheckExecutor::check_internal, cppcheck);
if (settings.exceptionHandling)
return check_wrapper_sig(*this, &CppCheckExecutor::check_internal, settings);
#endif
return check_internal(cppcheck);
return check_internal(settings);
}

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) {
Expand Down Expand Up @@ -246,9 +243,11 @@ bool CppCheckExecutor::reportSuppressions(const Settings &settings, const Suppre
/*
* That is a method which gets called from check_wrapper
* */
int CppCheckExecutor::check_internal(CppCheck& cppcheck) const
int CppCheckExecutor::check_internal(const Settings& settings) const
{
const auto& settings = cppcheck.settings();
CppCheck cppcheck(*mStdLogger, true, executeCommand);
cppcheck.settings() = settings; // this is a copy

auto& suppressions = cppcheck.settings().nomsg;

if (settings.reportProgress >= 0)
Expand Down Expand Up @@ -285,7 +284,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck) const
cppcheck.analyseWholeProgram(settings.buildDir, mFiles, mFileSettings);

if (settings.severity.isEnabled(Severity::information) || settings.checkConfiguration) {
const bool err = reportSuppressions(settings, settings.nomsg, cppcheck.isUnusedFunctionCheckEnabled(), mFiles, mFileSettings, *mStdLogger);
const bool err = reportSuppressions(settings, suppressions, cppcheck.isUnusedFunctionCheckEnabled(), mFiles, mFileSettings, *mStdLogger);
if (err && returnValue == 0)
returnValue = settings.exitCode;
}
Expand Down
9 changes: 4 additions & 5 deletions cli/cppcheckexecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <utility>
#include <vector>

class CppCheck;
class Settings;
class ErrorLogger;
class Suppressions;
Expand Down Expand Up @@ -88,21 +87,21 @@ class CppCheckExecutor {
* Wrapper around check_internal
* - installs optional platform dependent signal handling
*
* @param cppcheck cppcheck instance
* @param settings the settings
**/
int check_wrapper(CppCheck& cppcheck);
int check_wrapper(const Settings& settings);

/**
* Starts the checking.
*
* @param cppcheck cppcheck instance
* @param settings the settings
* @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(CppCheck& cppcheck) const;
int check_internal(const Settings& settings) const;

/**
* Filename associated with size of file
Expand Down
4 changes: 2 additions & 2 deletions cli/cppcheckexecutorseh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ namespace {
* TODO Check for multi-threading issues!
*
*/
int check_wrapper_seh(CppCheckExecutor& executor, int (CppCheckExecutor::*f)(CppCheck&) const, CppCheck& cppcheck)
int check_wrapper_seh(CppCheckExecutor& executor, int (CppCheckExecutor::*f)(const Settings&) const, const Settings& settings)
{
FILE *outputFile = CppCheckExecutor::getExceptionOutput();
__try {
return (&executor->*f)(cppcheck);
return (&executor->*f)(settings);
} __except (filterException(outputFile, GetExceptionCode(), GetExceptionInformation())) {
fputs("Please report this to the cppcheck developers!\n", outputFile);
return -1;
Expand Down
4 changes: 2 additions & 2 deletions cli/cppcheckexecutorseh.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
#ifdef USE_WINDOWS_SEH

class CppCheckExecutor;
class CppCheck;
class Settings;

int check_wrapper_seh(CppCheckExecutor& executor, int (CppCheckExecutor::*f)(CppCheck&) const, CppCheck& cppcheck);
int check_wrapper_seh(CppCheckExecutor& executor, int (CppCheckExecutor::*f)(const Settings&) const, const Settings& settings);

#endif

Expand Down
4 changes: 2 additions & 2 deletions cli/cppcheckexecutorsig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context)
}
}

int check_wrapper_sig(CppCheckExecutor& executor, int (CppCheckExecutor::*f)(CppCheck&) const, CppCheck& cppcheck)
int check_wrapper_sig(CppCheckExecutor& executor, int (CppCheckExecutor::*f)(const Settings&) const, const Settings& settings)
{
// determine stack vs. heap
char stackVariable;
Expand All @@ -321,7 +321,7 @@ int check_wrapper_sig(CppCheckExecutor& executor, int (CppCheckExecutor::*f)(Cpp
for (std::map<int, std::string>::const_iterator sig=listofsignals.cbegin(); sig!=listofsignals.cend(); ++sig) {
sigaction(sig->first, &act, nullptr);
}
return (executor.*f)(cppcheck);
return (executor.*f)(settings);
}

#endif
4 changes: 2 additions & 2 deletions cli/cppcheckexecutorsig.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
#if defined(USE_UNIX_SIGNAL_HANDLING)

class CppCheckExecutor;
class CppCheck;
class Settings;

int check_wrapper_sig(CppCheckExecutor& executor, int (CppCheckExecutor::*f)(CppCheck&) const, CppCheck& cppcheck);
int check_wrapper_sig(CppCheckExecutor& executor, int (CppCheckExecutor::*f)(const Settings&) const, const Settings& settings);

#endif // CPPCHECKEXECUTORSIG_H

Expand Down