From 1d3f9beb2169e149c01e1abb5baf46131f88c285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Sat, 25 Nov 2023 22:07:49 +0100 Subject: [PATCH] CppCheckExecutor: do not modify settings after they were passed to `CppCheck` (#5697) --- cli/cppcheckexecutor.cpp | 16 +++++++++------- cli/cppcheckexecutor.h | 2 +- cli/cppcheckexecutorseh.cpp | 2 +- cli/cppcheckexecutorseh.h | 2 +- cli/cppcheckexecutorsig.cpp | 2 +- cli/cppcheckexecutorsig.h | 2 +- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 832684c96..4320c020f 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -183,10 +183,13 @@ int CppCheckExecutor::check(int argc, const char* const argv[]) return EXIT_SUCCESS; } + settings.loadSummaries(); + mFiles = parser.getFiles(); mFileSettings = parser.getFileSettings(); mStdLogger = new StdLogger(settings); + CppCheck cppCheck(*mStdLogger, true, executeCommand); cppCheck.settings() = settings; @@ -230,9 +233,10 @@ bool CppCheckExecutor::reportSuppressions(const Settings &settings, bool unusedF /* * That is a method which gets called from check_wrapper * */ -int CppCheckExecutor::check_internal(CppCheck& cppcheck) +int CppCheckExecutor::check_internal(CppCheck& cppcheck) const { - Settings& settings = cppcheck.settings(); + const auto& settings = cppcheck.settings(); + auto& suppressions = cppcheck.settings().nomsg; if (settings.reportProgress >= 0) mStdLogger->resetLatestProgressOutputTime(); @@ -242,8 +246,6 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck) } if (!settings.buildDir.empty()) { - settings.loadSummaries(); - std::list fileNames; for (std::list>::const_iterator i = mFiles.cbegin(); i != mFiles.cend(); ++i) fileNames.emplace_back(i->first); @@ -256,13 +258,13 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck) unsigned int returnValue; if (settings.useSingleJob()) { // Single process - SingleExecutor executor(cppcheck, mFiles, mFileSettings, settings, settings.nomsg, *mStdLogger); + SingleExecutor executor(cppcheck, mFiles, mFileSettings, settings, suppressions, *mStdLogger); returnValue = executor.check(); } else { #if defined(THREADING_MODEL_THREAD) - ThreadExecutor executor(mFiles, mFileSettings, settings, settings.nomsg, *mStdLogger, CppCheckExecutor::executeCommand); + ThreadExecutor executor(mFiles, mFileSettings, settings, suppressions, *mStdLogger, CppCheckExecutor::executeCommand); #elif defined(THREADING_MODEL_FORK) - ProcessExecutor executor(mFiles, mFileSettings, settings, settings.nomsg, *mStdLogger, CppCheckExecutor::executeCommand); + ProcessExecutor executor(mFiles, mFileSettings, settings, suppressions, *mStdLogger, CppCheckExecutor::executeCommand); #endif returnValue = executor.check(); } diff --git a/cli/cppcheckexecutor.h b/cli/cppcheckexecutor.h index 34157ddfb..f54e49dee 100644 --- a/cli/cppcheckexecutor.h +++ b/cli/cppcheckexecutor.h @@ -101,7 +101,7 @@ protected: * given value is returned instead of default 0. * If no errors are found, 0 is returned. */ - int check_internal(CppCheck& cppcheck); + int check_internal(CppCheck& cppcheck) const; /** * Filename associated with size of file diff --git a/cli/cppcheckexecutorseh.cpp b/cli/cppcheckexecutorseh.cpp index 7f571bd53..9ec2df0a2 100644 --- a/cli/cppcheckexecutorseh.cpp +++ b/cli/cppcheckexecutorseh.cpp @@ -253,7 +253,7 @@ namespace { * TODO Check for multi-threading issues! * */ -int check_wrapper_seh(CppCheckExecutor& executor, int (CppCheckExecutor::*f)(CppCheck&), CppCheck& cppcheck) +int check_wrapper_seh(CppCheckExecutor& executor, int (CppCheckExecutor::*f)(CppCheck&) const, CppCheck& cppcheck) { FILE *outputFile = CppCheckExecutor::getExceptionOutput(); __try { diff --git a/cli/cppcheckexecutorseh.h b/cli/cppcheckexecutorseh.h index 56616d95a..93f51456c 100644 --- a/cli/cppcheckexecutorseh.h +++ b/cli/cppcheckexecutorseh.h @@ -26,7 +26,7 @@ class CppCheckExecutor; class CppCheck; -int check_wrapper_seh(CppCheckExecutor& executor, int (CppCheckExecutor::*f)(CppCheck&), CppCheck& cppcheck); +int check_wrapper_seh(CppCheckExecutor& executor, int (CppCheckExecutor::*f)(CppCheck&) const, CppCheck& cppcheck); #endif diff --git a/cli/cppcheckexecutorsig.cpp b/cli/cppcheckexecutorsig.cpp index 0d1156e0a..279a95633 100644 --- a/cli/cppcheckexecutorsig.cpp +++ b/cli/cppcheckexecutorsig.cpp @@ -298,7 +298,7 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context) } } -int check_wrapper_sig(CppCheckExecutor& executor, int (CppCheckExecutor::*f)(CppCheck&), CppCheck& cppcheck) +int check_wrapper_sig(CppCheckExecutor& executor, int (CppCheckExecutor::*f)(CppCheck&) const, CppCheck& cppcheck) { // determine stack vs. heap char stackVariable; diff --git a/cli/cppcheckexecutorsig.h b/cli/cppcheckexecutorsig.h index 4279378e4..5c8c161d2 100644 --- a/cli/cppcheckexecutorsig.h +++ b/cli/cppcheckexecutorsig.h @@ -26,7 +26,7 @@ class CppCheckExecutor; class CppCheck; -int check_wrapper_sig(CppCheckExecutor& executor, int (CppCheckExecutor::*f)(CppCheck&), CppCheck& cppcheck); +int check_wrapper_sig(CppCheckExecutor& executor, int (CppCheckExecutor::*f)(CppCheck&) const, CppCheck& cppcheck); #endif // CPPCHECKEXECUTORSIG_H