Skip to content

Commit

Permalink
got rid of output setters in SEH/signal code
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Oct 7, 2024
1 parent 25130ff commit 5b0a81f
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 33 deletions.
9 changes: 1 addition & 8 deletions cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,6 @@ int CppCheckExecutor::check(int argc, const char* const argv[])
return EXIT_SUCCESS;
}

#if defined(USE_WINDOWS_SEH)
set_seh_output(settings.exceptionOutput);
#endif
#if defined(USE_UNIX_SIGNAL_HANDLING)
set_signal_handler_output(settings.exceptionOutput);
#endif

settings.loadSummaries();

mFiles = parser.getFiles();
Expand All @@ -214,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);
}
Expand Down
9 changes: 1 addition & 8 deletions cli/cppcheckexecutorseh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,6 @@ namespace {
}
}

static FILE* sehOutput = stdout;

void set_seh_output(FILE* f)
{
sehOutput = f;
}

/**
* Signal/SEH handling
* Has to be clean for using with SEH on windows, i.e. no construction of C++ object instances is allowed!
Expand All @@ -267,7 +260,7 @@ void set_seh_output(FILE* f)
*/
int check_wrapper_seh(CppCheckExecutor& executor, int (CppCheckExecutor::*f)(const Settings&) const, const Settings& settings)
{
FILE *outputFile = sehOutput;
FILE * const outputFile = settings.exceptionOutput;
__try {
return (&executor->*f)(settings);
} __except (filterException(outputFile, GetExceptionCode(), GetExceptionInformation())) {
Expand Down
2 changes: 0 additions & 2 deletions cli/cppcheckexecutorseh.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
class CppCheckExecutor;
class Settings;

void set_seh_output(FILE* f);

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

#endif
Expand Down
11 changes: 3 additions & 8 deletions cli/signalhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 1 addition & 6 deletions cli/signalhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@

#include <cstdio>

/**
* @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

Expand Down
2 changes: 1 addition & 1 deletion test/signal/test-signalhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 5b0a81f

Please sign in to comment.