Skip to content

Commit 5198c05

Browse files
committed
--exception-handling now takes optional argument to choose between stdout and stderr for its output. stdout is new default value
1 parent 97894c2 commit 5198c05

4 files changed

Lines changed: 38 additions & 6 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ $(SRCDIR)/tokenlist.o: lib/tokenlist.cpp lib/cxx11emu.h lib/tokenlist.h lib/conf
390390
$(SRCDIR)/valueflow.o: lib/valueflow.cpp lib/cxx11emu.h lib/valueflow.h lib/errorlogger.h lib/config.h lib/suppressions.h lib/mathlib.h lib/settings.h lib/library.h lib/path.h lib/token.h lib/standards.h lib/timer.h lib/symboldatabase.h lib/tokenlist.h
391391
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -std=c++0x -c -o $(SRCDIR)/valueflow.o $(SRCDIR)/valueflow.cpp
392392

393-
cli/cmdlineparser.o: cli/cmdlineparser.cpp lib/cxx11emu.h cli/cmdlineparser.h lib/cppcheck.h lib/config.h lib/settings.h lib/library.h lib/path.h lib/mathlib.h lib/token.h lib/valueflow.h lib/suppressions.h lib/standards.h lib/timer.h lib/errorlogger.h cli/filelister.h lib/check.h lib/tokenize.h lib/tokenlist.h
393+
cli/cmdlineparser.o: cli/cmdlineparser.cpp lib/cxx11emu.h cli/cmdlineparser.h lib/cppcheck.h lib/config.h lib/settings.h lib/library.h lib/path.h lib/mathlib.h lib/token.h lib/valueflow.h lib/suppressions.h lib/standards.h lib/timer.h lib/errorlogger.h cli/cppcheckexecutor.h cli/filelister.h lib/check.h lib/tokenize.h lib/tokenlist.h
394394
$(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -std=c++0x -c -o cli/cmdlineparser.o cli/cmdlineparser.cpp
395395

396396
cli/cppcheckexecutor.o: cli/cppcheckexecutor.cpp lib/cxx11emu.h cli/cppcheckexecutor.h lib/errorlogger.h lib/config.h lib/suppressions.h cli/cmdlineparser.h lib/cppcheck.h lib/settings.h lib/library.h lib/path.h lib/mathlib.h lib/token.h lib/valueflow.h lib/standards.h lib/timer.h cli/filelister.h cli/pathmatch.h lib/preprocessor.h cli/threadexecutor.h

cli/cmdlineparser.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "cmdlineparser.h"
2020
#include "cppcheck.h"
21+
#include "cppcheckexecutor.h"
2122
#include "filelister.h"
2223
#include "path.h"
2324
#include "settings.h"
@@ -136,6 +137,11 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
136137
// (Experimental) exception handling inside cppcheck client
137138
else if (std::strcmp(argv[i], "--exception-handling") == 0)
138139
_settings->exceptionHandling = true;
140+
else if (std::strncmp(argv[i], "--exception-handling=", 21) == 0) {
141+
_settings->exceptionHandling = true;
142+
const std::string exceptionOutfilename=&(argv[i][21]);
143+
CppCheckExecutor::setExceptionOutput(exceptionOutfilename);
144+
}
139145

140146
// Inconclusive checking (still in testing phase)
141147
else if (std::strcmp(argv[i], "--inconclusive") == 0)

cli/cppcheckexecutor.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * /*context*
292292
const char * const signame = signal_name(signo);
293293
const char * const sigtext = strsignal(signo);
294294
bool bPrintCallstack=true;
295-
FILE* f=stderr;
295+
FILE* f=CppCheckExecutor::getExceptionOutput()=="stderr" ? stderr : stdout;
296296
fputs("Internal error: cppcheck received signal ", f);
297297
fputs(signame, f);
298298
fputs(", ", f);
@@ -334,15 +334,16 @@ static int filterException(int code, PEXCEPTION_POINTERS ex)
334334
{
335335
// TODO we should try to extract more information here
336336
// - address, read/write
337+
FILE *f = stdout;
337338
switch (ex->ExceptionRecord->ExceptionCode) {
338339
case EXCEPTION_ACCESS_VIOLATION:
339-
fprintf(stderr, "Internal error (EXCEPTION_ACCESS_VIOLATION)\n");
340+
fprintf(f, "Internal error (EXCEPTION_ACCESS_VIOLATION)\n");
340341
break;
341342
case EXCEPTION_IN_PAGE_ERROR:
342-
fprintf(stderr, "Internal error (EXCEPTION_IN_PAGE_ERROR)\n");
343+
fprintf(f, "Internal error (EXCEPTION_IN_PAGE_ERROR)\n");
343344
break;
344345
default:
345-
fprintf(stderr, "Internal error (%d)\n",
346+
fprintf(f, "Internal error (%d)\n",
346347
code);
347348
break;
348349
}
@@ -359,11 +360,12 @@ static int filterException(int code, PEXCEPTION_POINTERS ex)
359360
int CppCheckExecutor::check_wrapper(CppCheck& cppcheck, int argc, const char* const argv[])
360361
{
361362
#ifdef USE_WINDOWS_SEH
363+
FILE *f = stdout;
362364
__try {
363365
return check_internal(cppcheck, argc, argv);
364366
} __except (filterException(GetExceptionCode(), GetExceptionInformation())) {
365367
// reporting to stdout may not be helpful within a GUI application..
366-
fprintf(stderr, "Please report this to the cppcheck developers!\n");
368+
fprintf(f, "Please report this to the cppcheck developers!\n");
367369
return -1;
368370
}
369371
#elif defined(USE_UNIX_SIGNAL_HANDLING)
@@ -558,3 +560,13 @@ void CppCheckExecutor::reportErr(const ErrorLogger::ErrorMessage &msg)
558560
reportErr(msg.toString(_settings->_verbose, _settings->_outputFormat));
559561
}
560562
}
563+
564+
void CppCheckExecutor::setExceptionOutput(const std::string& fn)
565+
{
566+
exceptionOutput=fn;
567+
}
568+
const std::string& CppCheckExecutor::getExceptionOutput()
569+
{
570+
return exceptionOutput;
571+
}
572+
std::string CppCheckExecutor::exceptionOutput;

cli/cppcheckexecutor.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ class CppCheckExecutor : public ErrorLogger {
8787
*/
8888
static void reportStatus(std::size_t fileindex, std::size_t filecount, std::size_t sizedone, std::size_t sizetotal);
8989

90+
/**
91+
* @param fn file name to be used from exception handler
92+
*/
93+
static void setExceptionOutput(const std::string& fn);
94+
/**
95+
* @return file name to be used for output from exception handler
96+
*/
97+
static const std::string& getExceptionOutput();
98+
9099
protected:
91100

92101
/**
@@ -151,6 +160,11 @@ class CppCheckExecutor : public ErrorLogger {
151160
*/
152161
std::time_t time1;
153162

163+
/**
164+
* Output file name for exception handler
165+
*/
166+
static std::string exceptionOutput;
167+
154168
/**
155169
* Has --errorlist been given?
156170
*/

0 commit comments

Comments
 (0)