#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 { else {
// If the include path is not found, warn user and remove the non-existing path from the list. // If the include path is not found, warn user and remove the non-existing path from the list.
if (settings.isEnabled("information")) 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); iter = settings.includePaths.erase(iter);
} }
} }
@ -179,7 +179,6 @@ int CppCheckExecutor::check(int argc, const char* const argv[])
if (settings.terminated()) { if (settings.terminated()) {
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
if (cppCheck.settings().exceptionHandling) { if (cppCheck.settings().exceptionHandling) {
return check_wrapper(cppCheck, argc, argv); return check_wrapper(cppCheck, argc, argv);
} else { } else {
@ -199,13 +198,12 @@ std::size_t GetArrayLength(const T(&)[size])
#if defined(USE_UNIX_SIGNAL_HANDLING) #if defined(USE_UNIX_SIGNAL_HANDLING)
namespace {
/* /*
* Try to print the callstack. * Try to print the callstack.
* That is very sensitive to the operating system, hardware, compiler and runtime! * 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. * 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) #if defined(USE_UNIX_BACKTRACE_SUPPORT)
// 32 vs. 64bit // 32 vs. 64bit
@ -220,7 +218,6 @@ namespace {
maxdepth = std::min(maxdepth, currentdepth); maxdepth = std::min(maxdepth, currentdepth);
if (lowMem) { if (lowMem) {
fputs("Callstack (symbols only):\n", output); fputs("Callstack (symbols only):\n", output);
fflush(output);
backtrace_symbols_fd(array+offset, maxdepth, fd); backtrace_symbols_fd(array+offset, maxdepth, fd);
fflush(output); fflush(output);
} else { } else {
@ -272,16 +269,16 @@ namespace {
#endif #endif
} }
const size_t MYSTACKSIZE = 16*1024+SIGSTKSZ; // wild guess about a reasonable buffer static const size_t MYSTACKSIZE = 16*1024+SIGSTKSZ; // wild guess about a reasonable buffer
char mytstack[MYSTACKSIZE]= {0}; // alternative stack for signal handler static 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 bool bStackBelowHeap=false; // lame attempt to locate heap vs. stack address space. See CppCheckExecutor::check_wrapper()
/* /*
* \param[in] ptr address to be examined. * \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. * If unknown better return false.
*/ */
bool IsAddressOnStack(const void* ptr) static bool IsAddressOnStack(const void* ptr)
{ {
if (nullptr==ptr) if (nullptr==ptr)
return false; return false;
@ -300,7 +297,7 @@ namespace {
#define DECLARE_SIGNAL(x) << std::make_pair(x, #x) #define DECLARE_SIGNAL(x) << std::make_pair(x, #x)
typedef std::map<int, std::string> Signalmap_t; typedef std::map<int, std::string> Signalmap_t;
const Signalmap_t listofsignals = make_container< Signalmap_t > () static const Signalmap_t listofsignals = make_container< Signalmap_t > ()
DECLARE_SIGNAL(SIGABRT) DECLARE_SIGNAL(SIGABRT)
DECLARE_SIGNAL(SIGBUS) DECLARE_SIGNAL(SIGBUS)
DECLARE_SIGNAL(SIGFPE) DECLARE_SIGNAL(SIGFPE)
@ -317,10 +314,11 @@ namespace {
/* /*
* Entry pointer for signal handlers * Entry pointer for signal handlers
* It uses functions which are not safe to be called from a signal handler, * 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. * but when ending up here something went terribly wrong anyway.
* And all which is left is just printing some information and terminate. * 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; int type = -1;
pid_t killid = getpid(); pid_t killid = getpid();
@ -444,7 +442,7 @@ namespace {
(isaddressonstack)?" Stackoverflow?":""); (isaddressonstack)?" Stackoverflow?":"");
break; break;
case SIGINT: case SIGINT:
unexpectedSignal=false; unexpectedSignal=false; // legal usage: interrupt application via CTRL-C
fputs("cppcheck received signal ", output); fputs("cppcheck received signal ", output);
fputs(signame, output); fputs(signame, output);
printCallstack=true; printCallstack=true;
@ -471,7 +469,7 @@ namespace {
); );
break; break;
case SIGUSR1: case SIGUSR1:
unexpectedSignal=false; case SIGUSR2:
fputs("cppcheck received signal ", output); fputs("cppcheck received signal ", output);
fputs(signame, output); fputs(signame, output);
fputs(".\n", output); fputs(".\n", output);
@ -494,7 +492,6 @@ namespace {
signal(signo, SIG_DFL); signal(signo, SIG_DFL);
kill(killid, signo); kill(killid, signo);
} }
}
#endif #endif
#ifdef USE_WINDOWS_SEH #ifdef USE_WINDOWS_SEH