#7425 Broken XML output due to information about missing include paths. Use stdout for warning message (in alignment with other warnings messages). Minor refactoring (move some function from anon. namespace to static,etc.)

This commit is contained in:
Alexander Mai 2016-05-20 21:32:59 +02:00
parent d676022556
commit 80f445bf6f
1 changed files with 260 additions and 263 deletions

View File

@ -119,7 +119,7 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
else {
// If the include path is not found, warn user and remove the non-existing path from the list.
if (settings.isEnabled("information"))
std::cerr << "(information) Couldn't find path given by -I '" << path << '\'' << std::endl;
std::cout << "(information) Couldn't find path given by -I '" << path << '\'' << std::endl;
iter = settings.includePaths.erase(iter);
}
}
@ -179,7 +179,6 @@ int CppCheckExecutor::check(int argc, const char* const argv[])
if (settings.terminated()) {
return EXIT_SUCCESS;
}
if (cppCheck.settings().exceptionHandling) {
return check_wrapper(cppCheck, argc, argv);
} else {
@ -199,14 +198,13 @@ std::size_t GetArrayLength(const T(&)[size])
#if defined(USE_UNIX_SIGNAL_HANDLING)
namespace {
/*
/*
* Try to print the callstack.
* That is very sensitive to the operating system, hardware, compiler and runtime!
* The code is not meant for production environment, it's using functions not whitelisted for usage in a signal handler function.
*/
void print_stacktrace(FILE* output, bool demangling, int maxdepth, bool lowMem)
{
static void print_stacktrace(FILE* output, bool demangling, int maxdepth, bool lowMem)
{
#if defined(USE_UNIX_BACKTRACE_SUPPORT)
// 32 vs. 64bit
#define ADDRESSDISPLAYLENGTH ((sizeof(long)==8)?12:8)
@ -220,7 +218,6 @@ namespace {
maxdepth = std::min(maxdepth, currentdepth);
if (lowMem) {
fputs("Callstack (symbols only):\n", output);
fflush(output);
backtrace_symbols_fd(array+offset, maxdepth, fd);
fflush(output);
} else {
@ -270,19 +267,19 @@ namespace {
}
#undef ADDRESSDISPLAYLENGTH
#endif
}
}
const size_t MYSTACKSIZE = 16*1024+SIGSTKSZ; // wild guess about a reasonable buffer
char mytstack[MYSTACKSIZE]= {0}; // alternative stack for signal handler
bool bStackBelowHeap=false; // lame attempt to locate heap vs. stack address space. See CppCheckExecutor::check_wrapper()
static const size_t MYSTACKSIZE = 16*1024+SIGSTKSZ; // wild guess about a reasonable buffer
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()
/*
/*
* \param[in] ptr address to be examined.
* \return true if address is supposed to be on stack (contrary to heap or elsewhere). If ptr is 0 false will be returned.
* \return true if address is supposed to be on stack (contrary to heap). If ptr is 0 false will be returned.
* If unknown better return false.
*/
bool IsAddressOnStack(const void* ptr)
{
static bool IsAddressOnStack(const void* ptr)
{
if (nullptr==ptr)
return false;
char a;
@ -290,17 +287,17 @@ namespace {
return ptr < &a;
else
return ptr > &a;
}
}
/* (declare this list here, so it may be used in signal handlers in addition to main())
/* (declare this list here, so it may be used in signal handlers in addition to main())
* A list of signals available in ISO C
* Check out http://pubs.opengroup.org/onlinepubs/009695399/basedefs/signal.h.html
* For now we only want to detect abnormal behaviour for a few selected signals:
*/
#define DECLARE_SIGNAL(x) << std::make_pair(x, #x)
typedef std::map<int, std::string> Signalmap_t;
const Signalmap_t listofsignals = make_container< Signalmap_t > ()
typedef std::map<int, std::string> Signalmap_t;
static const Signalmap_t listofsignals = make_container< Signalmap_t > ()
DECLARE_SIGNAL(SIGABRT)
DECLARE_SIGNAL(SIGBUS)
DECLARE_SIGNAL(SIGFPE)
@ -314,14 +311,15 @@ namespace {
DECLARE_SIGNAL(SIGUSR2)
;
#undef DECLARE_SIGNAL
/*
/*
* Entry pointer for signal handlers
* It uses functions which are not safe to be called from a signal handler,
* (http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04 has a whitelist)
* but when ending up here something went terribly wrong anyway.
* And all which is left is just printing some information and terminate.
*/
void CppcheckSignalHandler(int signo, siginfo_t * info, void * context)
{
static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context)
{
int type = -1;
pid_t killid = getpid();
#if defined(__linux__) && defined(REG_ERR)
@ -444,7 +442,7 @@ namespace {
(isaddressonstack)?" Stackoverflow?":"");
break;
case SIGINT:
unexpectedSignal=false;
unexpectedSignal=false; // legal usage: interrupt application via CTRL-C
fputs("cppcheck received signal ", output);
fputs(signame, output);
printCallstack=true;
@ -471,7 +469,7 @@ namespace {
);
break;
case SIGUSR1:
unexpectedSignal=false;
case SIGUSR2:
fputs("cppcheck received signal ", output);
fputs(signame, output);
fputs(".\n", output);
@ -493,7 +491,6 @@ namespace {
// now let things proceed, shutdown and hopefully dump core for post-mortem analysis
signal(signo, SIG_DFL);
kill(killid, signo);
}
}
#endif