From 93c02ce826983a3f92a3bacedadb0d93011ef436 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Sat, 28 Nov 2015 10:49:08 +0100 Subject: [PATCH] Fixed compiler error introduced in previous commit and several MSVC warnings --- cli/cppcheckexecutor.cpp | 80 ++++++++++++++++++------------------- lib/checkstring.cpp | 2 +- lib/symboldatabase.cpp | 2 +- lib/templatesimplifier.cpp | 3 +- lib/tokenize.cpp | 2 +- test/testsymboldatabase.cpp | 8 ++-- 6 files changed, 48 insertions(+), 49 deletions(-) diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index b75fd5e83..0c3eb60e8 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -536,7 +536,7 @@ namespace { } - void PrintCallstack(FILE* output, PEXCEPTION_POINTERS ex) + void PrintCallstack(FILE* outputFile, PEXCEPTION_POINTERS ex) { if (!loadDbgHelp()) return; @@ -595,11 +595,11 @@ namespace { ++beyond_main; if (_tcscmp(undname, _T("main"))==0) beyond_main=0; - fprintf(output, + fprintf(outputFile, "%lu. 0x%08I64X in ", frame, (ULONG64)stack.AddrPC.Offset); - fputs((const char *)undname, output); - fputc('\n', output); + fputs((const char *)undname, outputFile); + fputc('\n', outputFile); if (0==stack.AddrReturn.Offset || beyond_main>2) // StackWalk64() sometimes doesn't reach any end... break; } @@ -608,24 +608,24 @@ namespace { hLibDbgHelp=0; } - void writeMemoryErrorDetails(FILE* output, PEXCEPTION_POINTERS ex, const char* description) + void writeMemoryErrorDetails(FILE* outputFile, PEXCEPTION_POINTERS ex, const char* description) { - fputs(description, output); - fprintf(output, " (instruction: 0x%p) ", ex->ExceptionRecord->ExceptionAddress); + fputs(description, outputFile); + fprintf(outputFile, " (instruction: 0x%p) ", ex->ExceptionRecord->ExceptionAddress); // Using %p for ULONG_PTR later on, so it must have size identical to size of pointer // This is not the universally portable solution but good enough for Win32/64 C_ASSERT(sizeof(void*) == sizeof(ex->ExceptionRecord->ExceptionInformation[1])); switch (ex->ExceptionRecord->ExceptionInformation[0]) { case 0: - fprintf(output, "reading from 0x%p", + fprintf(outputFile, "reading from 0x%p", reinterpret_cast(ex->ExceptionRecord->ExceptionInformation[1])); break; case 1: - fprintf(output, "writing to 0x%p", + fprintf(outputFile, "writing to 0x%p", reinterpret_cast(ex->ExceptionRecord->ExceptionInformation[1])); break; case 8: - fprintf(output, "data execution prevention at 0x%p", + fprintf(outputFile, "data execution prevention at 0x%p", reinterpret_cast(ex->ExceptionRecord->ExceptionInformation[1])); break; default: @@ -638,83 +638,83 @@ namespace { */ int filterException(int code, PEXCEPTION_POINTERS ex) { - FILE *output = stdout; - fputs("Internal error: ", output); + FILE *outputFile = stdout; + fputs("Internal error: ", outputFile); switch (ex->ExceptionRecord->ExceptionCode) { case EXCEPTION_ACCESS_VIOLATION: - writeMemoryErrorDetails(output, ex, "Access violation"); + writeMemoryErrorDetails(outputFile, ex, "Access violation"); break; case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: - fputs("Out of array bounds", output); + fputs("Out of array bounds", outputFile); break; case EXCEPTION_BREAKPOINT: - fputs("Breakpoint", output); + fputs("Breakpoint", outputFile); break; case EXCEPTION_DATATYPE_MISALIGNMENT: - fputs("Misaligned data", output); + fputs("Misaligned data", outputFile); break; case EXCEPTION_FLT_DENORMAL_OPERAND: - fputs("Denormalized floating-point value", output); + fputs("Denormalized floating-point value", outputFile); break; case EXCEPTION_FLT_DIVIDE_BY_ZERO: - fputs("Floating-point divide-by-zero", output); + fputs("Floating-point divide-by-zero", outputFile); break; case EXCEPTION_FLT_INEXACT_RESULT: - fputs("Inexact floating-point value", output); + fputs("Inexact floating-point value", outputFile); break; case EXCEPTION_FLT_INVALID_OPERATION: - fputs("Invalid floating-point operation", output); + fputs("Invalid floating-point operation", outputFile); break; case EXCEPTION_FLT_OVERFLOW: - fputs("Floating-point overflow", output); + fputs("Floating-point overflow", outputFile); break; case EXCEPTION_FLT_STACK_CHECK: - fputs("Floating-point stack overflow", output); + fputs("Floating-point stack overflow", outputFile); break; case EXCEPTION_FLT_UNDERFLOW: - fputs("Floating-point underflow", output); + fputs("Floating-point underflow", outputFile); break; case EXCEPTION_GUARD_PAGE: - fputs("Page-guard access", output); + fputs("Page-guard access", outputFile); break; case EXCEPTION_ILLEGAL_INSTRUCTION: - fputs("Illegal instruction", output); + fputs("Illegal instruction", outputFile); break; case EXCEPTION_IN_PAGE_ERROR: - writeMemoryErrorDetails(output, ex, "Invalid page access"); + writeMemoryErrorDetails(outputFile, ex, "Invalid page access"); break; case EXCEPTION_INT_DIVIDE_BY_ZERO: - fputs("Integer divide-by-zero", output); + fputs("Integer divide-by-zero", outputFile); break; case EXCEPTION_INT_OVERFLOW: - fputs("Integer overflow", output); + fputs("Integer overflow", outputFile); break; case EXCEPTION_INVALID_DISPOSITION: - fputs("Invalid exception dispatcher", output); + fputs("Invalid exception dispatcher", outputFile); break; case EXCEPTION_INVALID_HANDLE: - fputs("Invalid handle", output); + fputs("Invalid handle", outputFile); break; case EXCEPTION_NONCONTINUABLE_EXCEPTION: - fputs("Non-continuable exception", output); + fputs("Non-continuable exception", outputFile); break; case EXCEPTION_PRIV_INSTRUCTION: - fputs("Invalid instruction", output); + fputs("Invalid instruction", outputFile); break; case EXCEPTION_SINGLE_STEP: - fputs("Single instruction step", output); + fputs("Single instruction step", outputFile); break; case EXCEPTION_STACK_OVERFLOW: - fputs("Stack overflow", output); + fputs("Stack overflow", outputFile); break; default: - fprintf(output, "Unknown exception (%d)\n", + fprintf(outputFile, "Unknown exception (%d)\n", code); break; } - fputc('\n', output); - PrintCallstack(output, ex); - fflush(output); + fputc('\n', outputFile); + PrintCallstack(outputFile, ex); + fflush(outputFile); return EXCEPTION_EXECUTE_HANDLER; } } @@ -729,12 +729,12 @@ namespace { int CppCheckExecutor::check_wrapper(CppCheck& cppcheck, int argc, const char* const argv[]) { #ifdef USE_WINDOWS_SEH - FILE *output = stdout; + FILE *outputFile = stdout; __try { return check_internal(cppcheck, argc, argv); } __except (filterException(GetExceptionCode(), GetExceptionInformation())) { // reporting to stdout may not be helpful within a GUI application... - fputs("Please report this to the cppcheck developers!\n", output); + fputs("Please report this to the cppcheck developers!\n", outputFile); return -1; } #elif defined(USE_UNIX_SIGNAL_HANDLING) diff --git a/lib/checkstring.cpp b/lib/checkstring.cpp index 0c4e794c3..2d0662e0b 100644 --- a/lib/checkstring.cpp +++ b/lib/checkstring.cpp @@ -267,7 +267,7 @@ void CheckString::checkIncorrectStringCompare() tok = tok->next()->link(); if (Token::simpleMatch(tok, ". substr (") && Token::Match(tok->tokAt(3)->nextArgument(), "%num% )")) { - MathLib::bigint clen = MathLib::toLongNumber(tok->linkAt(2)->strAt(-1)); + MathLib::biguint clen = MathLib::toULongNumber(tok->linkAt(2)->strAt(-1)); const Token* begin = tok->previous(); for (;;) { // Find start of statement while (begin->link() && Token::Match(begin, "]|)|>")) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 922ca951e..24f62f944 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -3922,7 +3922,7 @@ std::string ValueType::str() const ret += " double"; else if (type == LONGDOUBLE) ret += " long double"; - for (int p = 0; p < pointer; p++) { + for (unsigned int p = 0; p < pointer; p++) { ret += " *"; if (constness & (2 << p)) ret += " const"; diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index defe5499f..447608281 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -1046,8 +1046,7 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens) } if (Token::Match(tok->previous(), "(|&&|%oror% %char% %comp% %num% &&|%oror%|)")) { - int c = MathLib::toLongNumber(tok->str()); - tok->str(MathLib::toString(c)); + tok->str(MathLib::toString(MathLib::toLongNumber(tok->str()))); } if (tok->isNumber()) { diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index ba0b65584..303c6a6c7 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2188,7 +2188,7 @@ void Tokenizer::arraySize() } else if (Token::Match(tok, "%var% [ ] = {")) { - unsigned int sz = 1; + MathLib::biguint sz = 1; tok = tok->next(); Token *end = tok->linkAt(3); for (Token *tok2 = tok->tokAt(4); tok2 && tok2 != end; tok2 = tok2->next()) { diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 9e9e6d76f..317dd2df3 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -2187,8 +2187,8 @@ private: if (db) { ASSERT_EQUALS(2, db->scopeList.size()); ASSERT_EQUALS(2, db->getVariableListSize()-1); - ASSERT(db->getVariableFromVarId(1)); - ASSERT(db->getVariableFromVarId(2)); + ASSERT(db->getVariableFromVarId(1) != nullptr); + ASSERT(db->getVariableFromVarId(2) != nullptr); } } @@ -2198,8 +2198,8 @@ private: ASSERT(db != nullptr); if (db) { - ASSERT(db->getVariableFromVarId(1)); - ASSERT(db->getVariableFromVarId(2)); + ASSERT(db->getVariableFromVarId(1) != nullptr); + ASSERT(db->getVariableFromVarId(2) != nullptr); ASSERT_EQUALS(false, db->getVariableFromVarId(1)->isClass()); ASSERT_EQUALS(false, db->getVariableFromVarId(2)->isClass()); }