From 5814c3b84cb3ea43c022c3c1f0886ab48904d61a Mon Sep 17 00:00:00 2001 From: amai2012 Date: Sun, 28 Jun 2015 19:20:16 +0200 Subject: [PATCH] Fix some compiler warnings with VS Minor refactoring on Windows SEH code. --- cli/cppcheckexecutor.cpp | 13 +++++++------ lib/checkbufferoverrun.cpp | 1 + lib/checkcondition.cpp | 13 +++++-------- lib/errorlogger.cpp | 2 +- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 40614c6c5..848ac4445 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -508,7 +508,7 @@ static bool loadDbgHelp() { hLibDbgHelp = ::LoadLibraryW(L"Dbghelp.dll"); if (!hLibDbgHelp) - return true; + return false; pStackWalk64 = (fpStackWalk64) ::GetProcAddress(hLibDbgHelp, "StackWalk64"); pSymGetModuleBase64 = (fpSymGetModuleBase64) ::GetProcAddress(hLibDbgHelp, "SymGetModuleBase64"); pSymGetSymFromAddr64 = (fpSymGetSymFromAddr64) ::GetProcAddress(hLibDbgHelp, "SymGetSymFromAddr64"); @@ -583,7 +583,7 @@ static void PrintCallstack(FILE* f, PEXCEPTION_POINTERS ex) "%lu. 0x%08I64X in ", frame, (ULONG64)stack.AddrPC.Offset); fputs((const char *)undname, f); - fputs("\n", f); + fputc('\n', f); if (0==stack.AddrReturn.Offset || beyond_main>2) // StackWalk64() sometimes doesn't reach any end... break; } @@ -595,20 +595,21 @@ static void PrintCallstack(FILE* f, PEXCEPTION_POINTERS ex) static void writeMemoryErrorDetails(FILE* f, PEXCEPTION_POINTERS ex, const char* description) { fputs(description, f); + fprintf(f, " (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(f, " reading from 0x%p", + fprintf(f, "reading from 0x%p", ex->ExceptionRecord->ExceptionInformation[1]); break; case 1: - fprintf(f, " writing at 0x%p", + fprintf(f, "writing to 0x%p", ex->ExceptionRecord->ExceptionInformation[1]); break; case 8: - fprintf(f, " data execution prevention at 0x%p", + fprintf(f, "data execution prevention at 0x%p", ex->ExceptionRecord->ExceptionInformation[1]); break; default: @@ -695,7 +696,7 @@ static int filterException(int code, PEXCEPTION_POINTERS ex) code); break; } - fputs("\n", f); + fputc('\n', f); PrintCallstack(f, ex); fflush(f); return EXCEPTION_EXECUTE_HANDLER; diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 79c694ded..7e5afe603 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -1801,6 +1801,7 @@ Check::FileInfo* CheckBufferOverrun::getFileInfo(const Tokenizer *tokenizer, con void CheckBufferOverrun::analyseWholeProgram(const std::list &fileInfo, const Settings& settings, ErrorLogger &errorLogger) { + (void)settings; // Merge all fileInfo MyFileInfo all; for (std::list::const_iterator it = fileInfo.begin(); it != fileInfo.end(); ++it) { diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index aa1de2779..161977b39 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -552,14 +552,11 @@ static bool checkFloatRelation(const std::string &op, const double value1, const template T getvalue3(const T value1, const T value2) { - if (std::numeric_limits::is_integer) { - const T min = std::min(value1, value2); - if (min== std::numeric_limits::max()) - return min; - else - return min+1; // see #5895 - } - return (value1 + value2) / (T)2; + const T min = std::min(value1, value2); + if (min== std::numeric_limits::max()) + return min; + else + return min+1; // see #5895 } template<> diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index 52f529a72..b151a450d 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -159,7 +159,7 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data) _id = results[0]; _severity = Severity::fromString(results[1]); - _cwe = MathLib::toULongNumber(results[2]); + _cwe = (unsigned)MathLib::toULongNumber(results[2]); _shortMessage = results[3]; _verboseMessage = results[4];