diff --git a/Makefile b/Makefile index 827f5233221..96c3557ac1c 100644 --- a/Makefile +++ b/Makefile @@ -759,7 +759,7 @@ $(libcppdir)/vf_unknownfunctionreturn.o: lib/vf_unknownfunctionreturn.cpp lib/ad $(libcppdir)/vfvalue.o: lib/vfvalue.cpp lib/config.h lib/errortypes.h lib/mathlib.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/vfvalue.h $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vfvalue.cpp -cli/cmdlineparser.o: cli/cmdlineparser.cpp cli/cmdlinelogger.h cli/cmdlineparser.h cli/cppcheckexecutor.h cli/filelister.h externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/analyzerinfo.h lib/check.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/pathmatch.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/utils.h lib/xml.h +cli/cmdlineparser.o: cli/cmdlineparser.cpp cli/cmdlinelogger.h cli/cmdlineparser.h cli/filelister.h externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/analyzerinfo.h lib/check.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/pathmatch.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/utils.h lib/xml.h $(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/cmdlineparser.cpp cli/cppcheckexecutor.o: cli/cppcheckexecutor.cpp cli/cmdlinelogger.h cli/cmdlineparser.h cli/cppcheckexecutor.h cli/cppcheckexecutorseh.h cli/executor.h cli/processexecutor.h cli/signalhandler.h cli/singleexecutor.h cli/threadexecutor.h lib/addoninfo.h lib/analyzerinfo.h lib/check.h lib/checkersreport.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h @@ -840,7 +840,7 @@ test/testclangimport.o: test/testclangimport.cpp lib/addoninfo.h lib/check.h lib test/testclass.o: test/testclass.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/checkclass.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testclass.cpp -test/testcmdlineparser.o: test/testcmdlineparser.cpp cli/cmdlinelogger.h cli/cmdlineparser.h cli/cppcheckexecutor.h externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h test/helpers.h test/redirect.h +test/testcmdlineparser.o: test/testcmdlineparser.cpp cli/cmdlinelogger.h cli/cmdlineparser.h externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h test/helpers.h test/redirect.h $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testcmdlineparser.cpp test/testcolor.o: test/testcolor.cpp lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h test/fixture.h diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 9634ecd61b4..11923440ea6 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -23,7 +23,6 @@ #include "color.h" #include "config.h" #include "cppcheck.h" -#include "cppcheckexecutor.h" #include "errorlogger.h" #include "errortypes.h" #include "filelister.h" @@ -637,7 +636,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a return Result::Fail; } mSettings.exceptionHandling = true; - CppCheckExecutor::setExceptionOutput((exceptionOutfilename == "stderr") ? stderr : stdout); + mSettings.exceptionOutput = (exceptionOutfilename == "stderr") ? stderr : stdout; #else mLogger.printError("Option --exception-handling is not supported since Cppcheck has not been built with any exception handling enabled."); return Result::Fail; diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index a39685f03f4..48edcd1ff4d 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -176,12 +176,6 @@ namespace { }; } -// TODO: do not directly write to stdout - -#if defined(USE_WINDOWS_SEH) || defined(USE_UNIX_SIGNAL_HANDLING) -/*static*/ FILE* CppCheckExecutor::mExceptionOutput = stdout; -#endif - int CppCheckExecutor::check(int argc, const char* const argv[]) { Settings settings; @@ -213,7 +207,7 @@ int CppCheckExecutor::check_wrapper(const Settings& settings) return check_wrapper_seh(*this, &CppCheckExecutor::check_internal, settings); #elif defined(USE_UNIX_SIGNAL_HANDLING) if (settings.exceptionHandling) - register_signal_handler(); + register_signal_handler(settings.exceptionOutput); #endif return check_internal(settings); } @@ -453,22 +447,6 @@ void StdLogger::reportErr(const ErrorMessage &msg) reportErr(msg.toString(mSettings.verbose, mSettings.templateFormat, mSettings.templateLocation)); } -#if defined(USE_WINDOWS_SEH) || defined(USE_UNIX_SIGNAL_HANDLING) -void CppCheckExecutor::setExceptionOutput(FILE* exceptionOutput) -{ - mExceptionOutput = exceptionOutput; -#if defined(USE_UNIX_SIGNAL_HANDLING) - set_signal_handler_output(mExceptionOutput); -#endif -} - -// cppcheck-suppress unusedFunction - only used by USE_WINDOWS_SEH code -FILE* CppCheckExecutor::getExceptionOutput() -{ - return mExceptionOutput; -} -#endif - /** * Execute a shell command and read the output from it. Returns true if command terminated successfully. */ diff --git a/cli/cppcheckexecutor.h b/cli/cppcheckexecutor.h index 16076cab035..b4df74b85ad 100644 --- a/cli/cppcheckexecutor.h +++ b/cli/cppcheckexecutor.h @@ -19,10 +19,8 @@ #ifndef CPPCHECKEXECUTOR_H #define CPPCHECKEXECUTOR_H -#include "config.h" #include "filesettings.h" -#include #include #include #include @@ -62,15 +60,6 @@ class CppCheckExecutor { */ int check(int argc, const char* const argv[]); - /** - * @param exceptionOutput Output file - */ - static void setExceptionOutput(FILE* exceptionOutput); - /** - * @return file name to be used for output from exception handler. Has to be either "stdout" or "stderr". - */ - static FILE* getExceptionOutput(); - private: /** @@ -108,13 +97,6 @@ class CppCheckExecutor { std::list mFiles; std::list mFileSettings; - -#if defined(USE_WINDOWS_SEH) || defined(USE_UNIX_SIGNAL_HANDLING) - /** - * Output file name for exception handler - */ - static FILE* mExceptionOutput; -#endif }; #endif // CPPCHECKEXECUTOR_H diff --git a/cli/cppcheckexecutorseh.cpp b/cli/cppcheckexecutorseh.cpp index 4de4a67c56d..74a04845d44 100644 --- a/cli/cppcheckexecutorseh.cpp +++ b/cli/cppcheckexecutorseh.cpp @@ -260,7 +260,7 @@ namespace { */ int check_wrapper_seh(CppCheckExecutor& executor, int (CppCheckExecutor::*f)(const Settings&) const, const Settings& settings) { - FILE *outputFile = CppCheckExecutor::getExceptionOutput(); + FILE * const outputFile = settings.exceptionOutput; __try { return (&executor->*f)(settings); } __except (filterException(outputFile, GetExceptionCode(), GetExceptionInformation())) { diff --git a/cli/signalhandler.cpp b/cli/signalhandler.cpp index 15dda424de0..faf324f52d4 100644 --- a/cli/signalhandler.cpp +++ b/cli/signalhandler.cpp @@ -56,12 +56,7 @@ static constexpr size_t MYSTACKSIZE = 16*1024+SIGSTKSZ; // wild guess about a re #endif static char mytstack[MYSTACKSIZE]= {0}; // alternative stack for signal handler static bool bStackBelowHeap=false; // lame attempt to locate heap vs. stack address space. See CppCheckExecutor::check_wrapper() -static FILE* signalOutput = stdout; - -void set_signal_handler_output(FILE* f) -{ - signalOutput = f; -} +static FILE* signalOutput = stdout; // TODO: get rid of this /** * \param[in] ptr address to be examined. @@ -299,9 +294,9 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context) } } -void register_signal_handler() +void register_signal_handler(FILE * const output) { - FILE * const output = signalOutput; + signalOutput = output; // determine stack vs. heap char stackVariable; diff --git a/cli/signalhandler.h b/cli/signalhandler.h index c3df37328c8..df5a6120fe8 100644 --- a/cli/signalhandler.h +++ b/cli/signalhandler.h @@ -25,12 +25,7 @@ #include -/** - * @param f Output file - */ -void set_signal_handler_output(FILE* f); - -void register_signal_handler(); +void register_signal_handler(FILE* output); #endif // USE_UNIX_SIGNAL_HANDLING diff --git a/lib/settings.h b/lib/settings.h index ef4207cced9..d886cab0a40 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -211,6 +211,8 @@ class CPPCHECKLIB WARN_UNUSED Settings { #if defined(USE_WINDOWS_SEH) || defined(USE_UNIX_SIGNAL_HANDLING) /** @brief Is --exception-handling given */ bool exceptionHandling{}; + + FILE* exceptionOutput = stdout; #endif enum class ExecutorType : std::uint8_t diff --git a/test/signal/test-signalhandler.cpp b/test/signal/test-signalhandler.cpp index 37f8907faf8..75115f35096 100644 --- a/test/signal/test-signalhandler.cpp +++ b/test/signal/test-signalhandler.cpp @@ -60,7 +60,7 @@ int main(int argc, const char * const argv[]) if (argc != 2) return 1; - register_signal_handler(); + register_signal_handler(stdout); if (strcmp(argv[1], "assert") == 0) my_assert(); diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index 08dbe16b4db..4e262b8edb7 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -19,7 +19,6 @@ #include "cmdlinelogger.h" #include "cmdlineparser.h" #include "config.h" -#include "cppcheckexecutor.h" #include "errorlogger.h" #include "errortypes.h" #include "helpers.h" @@ -1911,28 +1910,25 @@ class TestCmdlineParser : public TestFixture { void exceptionhandling() { REDIRECT; const char * const argv[] = {"cppcheck", "--exception-handling", "file.cpp"}; - CppCheckExecutor::setExceptionOutput(stderr); ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(settings->exceptionHandling); - ASSERT_EQUALS(stderr, CppCheckExecutor::getExceptionOutput()); + ASSERT_EQUALS(stdout, settings->exceptionOutput); } void exceptionhandling2() { REDIRECT; const char * const argv[] = {"cppcheck", "--exception-handling=stderr", "file.cpp"}; - CppCheckExecutor::setExceptionOutput(stdout); ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(settings->exceptionHandling); - ASSERT_EQUALS(stderr, CppCheckExecutor::getExceptionOutput()); + ASSERT_EQUALS(stderr, settings->exceptionOutput); } void exceptionhandling3() { REDIRECT; const char * const argv[] = {"cppcheck", "--exception-handling=stdout", "file.cpp"}; - CppCheckExecutor::setExceptionOutput(stderr); ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); ASSERT(settings->exceptionHandling); - ASSERT_EQUALS(stdout, CppCheckExecutor::getExceptionOutput()); + ASSERT_EQUALS(stdout, settings->exceptionOutput); } void exceptionhandlingInvalid() {