Skip to content

Commit 1855f5c

Browse files
authored
moved exception output file descriptor to Settings / got rid of output setters in SEH/signal code (#6868)
1 parent 629ec44 commit 1855f5c

10 files changed

Lines changed: 15 additions & 68 deletions

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ $(libcppdir)/vf_unknownfunctionreturn.o: lib/vf_unknownfunctionreturn.cpp lib/ad
759759
$(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
760760
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vfvalue.cpp
761761

762-
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
762+
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
763763
$(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/cmdlineparser.cpp
764764

765765
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
840840
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
841841
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testclass.cpp
842842

843-
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
843+
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
844844
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testcmdlineparser.cpp
845845

846846
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

cli/cmdlineparser.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "color.h"
2424
#include "config.h"
2525
#include "cppcheck.h"
26-
#include "cppcheckexecutor.h"
2726
#include "errorlogger.h"
2827
#include "errortypes.h"
2928
#include "filelister.h"
@@ -637,7 +636,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
637636
return Result::Fail;
638637
}
639638
mSettings.exceptionHandling = true;
640-
CppCheckExecutor::setExceptionOutput((exceptionOutfilename == "stderr") ? stderr : stdout);
639+
mSettings.exceptionOutput = (exceptionOutfilename == "stderr") ? stderr : stdout;
641640
#else
642641
mLogger.printError("Option --exception-handling is not supported since Cppcheck has not been built with any exception handling enabled.");
643642
return Result::Fail;

cli/cppcheckexecutor.cpp

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,6 @@ namespace {
176176
};
177177
}
178178

179-
// TODO: do not directly write to stdout
180-
181-
#if defined(USE_WINDOWS_SEH) || defined(USE_UNIX_SIGNAL_HANDLING)
182-
/*static*/ FILE* CppCheckExecutor::mExceptionOutput = stdout;
183-
#endif
184-
185179
int CppCheckExecutor::check(int argc, const char* const argv[])
186180
{
187181
Settings settings;
@@ -213,7 +207,7 @@ int CppCheckExecutor::check_wrapper(const Settings& settings)
213207
return check_wrapper_seh(*this, &CppCheckExecutor::check_internal, settings);
214208
#elif defined(USE_UNIX_SIGNAL_HANDLING)
215209
if (settings.exceptionHandling)
216-
register_signal_handler();
210+
register_signal_handler(settings.exceptionOutput);
217211
#endif
218212
return check_internal(settings);
219213
}
@@ -453,22 +447,6 @@ void StdLogger::reportErr(const ErrorMessage &msg)
453447
reportErr(msg.toString(mSettings.verbose, mSettings.templateFormat, mSettings.templateLocation));
454448
}
455449

456-
#if defined(USE_WINDOWS_SEH) || defined(USE_UNIX_SIGNAL_HANDLING)
457-
void CppCheckExecutor::setExceptionOutput(FILE* exceptionOutput)
458-
{
459-
mExceptionOutput = exceptionOutput;
460-
#if defined(USE_UNIX_SIGNAL_HANDLING)
461-
set_signal_handler_output(mExceptionOutput);
462-
#endif
463-
}
464-
465-
// cppcheck-suppress unusedFunction - only used by USE_WINDOWS_SEH code
466-
FILE* CppCheckExecutor::getExceptionOutput()
467-
{
468-
return mExceptionOutput;
469-
}
470-
#endif
471-
472450
/**
473451
* Execute a shell command and read the output from it. Returns true if command terminated successfully.
474452
*/

cli/cppcheckexecutor.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919
#ifndef CPPCHECKEXECUTOR_H
2020
#define CPPCHECKEXECUTOR_H
2121

22-
#include "config.h"
2322
#include "filesettings.h"
2423

25-
#include <cstdio>
2624
#include <list>
2725
#include <string>
2826
#include <vector>
@@ -62,15 +60,6 @@ class CppCheckExecutor {
6260
*/
6361
int check(int argc, const char* const argv[]);
6462

65-
/**
66-
* @param exceptionOutput Output file
67-
*/
68-
static void setExceptionOutput(FILE* exceptionOutput);
69-
/**
70-
* @return file name to be used for output from exception handler. Has to be either "stdout" or "stderr".
71-
*/
72-
static FILE* getExceptionOutput();
73-
7463
private:
7564

7665
/**
@@ -108,13 +97,6 @@ class CppCheckExecutor {
10897
std::list<FileWithDetails> mFiles;
10998

11099
std::list<FileSettings> mFileSettings;
111-
112-
#if defined(USE_WINDOWS_SEH) || defined(USE_UNIX_SIGNAL_HANDLING)
113-
/**
114-
* Output file name for exception handler
115-
*/
116-
static FILE* mExceptionOutput;
117-
#endif
118100
};
119101

120102
#endif // CPPCHECKEXECUTOR_H

cli/cppcheckexecutorseh.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ namespace {
260260
*/
261261
int check_wrapper_seh(CppCheckExecutor& executor, int (CppCheckExecutor::*f)(const Settings&) const, const Settings& settings)
262262
{
263-
FILE *outputFile = CppCheckExecutor::getExceptionOutput();
263+
FILE * const outputFile = settings.exceptionOutput;
264264
__try {
265265
return (&executor->*f)(settings);
266266
} __except (filterException(outputFile, GetExceptionCode(), GetExceptionInformation())) {

cli/signalhandler.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,7 @@ static constexpr size_t MYSTACKSIZE = 16*1024+SIGSTKSZ; // wild guess about a re
5656
#endif
5757
static char mytstack[MYSTACKSIZE]= {0}; // alternative stack for signal handler
5858
static bool bStackBelowHeap=false; // lame attempt to locate heap vs. stack address space. See CppCheckExecutor::check_wrapper()
59-
static FILE* signalOutput = stdout;
60-
61-
void set_signal_handler_output(FILE* f)
62-
{
63-
signalOutput = f;
64-
}
59+
static FILE* signalOutput = stdout; // TODO: get rid of this
6560

6661
/**
6762
* \param[in] ptr address to be examined.
@@ -299,9 +294,9 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context)
299294
}
300295
}
301296

302-
void register_signal_handler()
297+
void register_signal_handler(FILE * const output)
303298
{
304-
FILE * const output = signalOutput;
299+
signalOutput = output;
305300

306301
// determine stack vs. heap
307302
char stackVariable;

cli/signalhandler.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@
2525

2626
#include <cstdio>
2727

28-
/**
29-
* @param f Output file
30-
*/
31-
void set_signal_handler_output(FILE* f);
32-
33-
void register_signal_handler();
28+
void register_signal_handler(FILE* output);
3429

3530
#endif // USE_UNIX_SIGNAL_HANDLING
3631

lib/settings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ class CPPCHECKLIB WARN_UNUSED Settings {
211211
#if defined(USE_WINDOWS_SEH) || defined(USE_UNIX_SIGNAL_HANDLING)
212212
/** @brief Is --exception-handling given */
213213
bool exceptionHandling{};
214+
215+
FILE* exceptionOutput = stdout;
214216
#endif
215217

216218
enum class ExecutorType : std::uint8_t

test/signal/test-signalhandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ int main(int argc, const char * const argv[])
6060
if (argc != 2)
6161
return 1;
6262

63-
register_signal_handler();
63+
register_signal_handler(stdout);
6464

6565
if (strcmp(argv[1], "assert") == 0)
6666
my_assert();

test/testcmdlineparser.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "cmdlinelogger.h"
2020
#include "cmdlineparser.h"
2121
#include "config.h"
22-
#include "cppcheckexecutor.h"
2322
#include "errorlogger.h"
2423
#include "errortypes.h"
2524
#include "helpers.h"
@@ -1911,28 +1910,25 @@ class TestCmdlineParser : public TestFixture {
19111910
void exceptionhandling() {
19121911
REDIRECT;
19131912
const char * const argv[] = {"cppcheck", "--exception-handling", "file.cpp"};
1914-
CppCheckExecutor::setExceptionOutput(stderr);
19151913
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv));
19161914
ASSERT(settings->exceptionHandling);
1917-
ASSERT_EQUALS(stderr, CppCheckExecutor::getExceptionOutput());
1915+
ASSERT_EQUALS(stdout, settings->exceptionOutput);
19181916
}
19191917

19201918
void exceptionhandling2() {
19211919
REDIRECT;
19221920
const char * const argv[] = {"cppcheck", "--exception-handling=stderr", "file.cpp"};
1923-
CppCheckExecutor::setExceptionOutput(stdout);
19241921
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv));
19251922
ASSERT(settings->exceptionHandling);
1926-
ASSERT_EQUALS(stderr, CppCheckExecutor::getExceptionOutput());
1923+
ASSERT_EQUALS(stderr, settings->exceptionOutput);
19271924
}
19281925

19291926
void exceptionhandling3() {
19301927
REDIRECT;
19311928
const char * const argv[] = {"cppcheck", "--exception-handling=stdout", "file.cpp"};
1932-
CppCheckExecutor::setExceptionOutput(stderr);
19331929
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv));
19341930
ASSERT(settings->exceptionHandling);
1935-
ASSERT_EQUALS(stdout, CppCheckExecutor::getExceptionOutput());
1931+
ASSERT_EQUALS(stdout, settings->exceptionOutput);
19361932
}
19371933

19381934
void exceptionhandlingInvalid() {

0 commit comments

Comments
 (0)