From 433f4640a9639eefb3270ce51619055230605b17 Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Sun, 30 Oct 2011 18:34:49 +0100 Subject: [PATCH] Fix some GCC warnings regarding the sign conversion. --- cli/cppcheckexecutor.cpp | 7 ++++--- lib/checkbufferoverrun.cpp | 2 +- lib/checkclass.cpp | 10 +++++----- lib/checkinternal.cpp | 4 ++-- lib/checkstl.cpp | 4 ++-- lib/tokenize.cpp | 2 +- tools/dmake.cpp | 7 ++++--- 7 files changed, 19 insertions(+), 17 deletions(-) diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 9f73fc031..6c47afe62 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -26,6 +26,7 @@ #include // EXIT_SUCCESS and EXIT_FAILURE #include #include +#include #include "cmdlineparser.h" #include "filelister.h" @@ -106,7 +107,7 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c bool warned = false; std::vector ignored = parser.GetIgnoredPaths(); std::vector::iterator iterIgnored = ignored.begin(); - for (int i = (int)ignored.size() - 1; i >= 0; i--) { + for (unsigned int i = ignored.size() - 1; i != UINT_MAX; --i) { const std::string extension = Path::getFilenameExtension(ignored[i]); if (extension == ".h" || extension == ".hpp") { ignored.erase(iterIgnored + i); @@ -120,14 +121,14 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c PathMatch matcher(parser.GetIgnoredPaths()); std::vector::iterator iterBegin = filenames.begin(); - for (int i = (int)filenames.size() - 1; i >= 0; i--) { + for (unsigned int i = filenames.size() - 1; i != UINT_MAX; i--) { #if defined(_WIN32) // For Windows we want case-insensitive path matching const bool caseSensitive = false; #else const bool caseSensitive = true; #endif - if (matcher.Match(filenames[(unsigned int)i], caseSensitive)) + if (matcher.Match(filenames[i], caseSensitive)) filenames.erase(iterBegin + i); } } else { diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 22fd13701..ba50a0de6 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -1212,7 +1212,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo void CheckBufferOverrun::checkReadlinkBufferUsage(const Token* tok, const Token *scope_begin, const MathLib::bigint total_size, const bool is_readlinkat) { - unsigned int param_offset = is_readlinkat ? 2 : 0; + unsigned char param_offset = is_readlinkat ? 2 : 0; const std::string funcname = is_readlinkat ? "readlinkat" : "readlink"; const MathLib::bigint n = MathLib::toLongNumber(tok->strAt(6 + param_offset)); diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 85809b2f5..c46210835 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1353,24 +1353,24 @@ bool CheckClass::isMemberVar(const Scope *scope, const Token *tok) return false; } -static int countParameters(const Token *tok) +static unsigned int countParameters(const Token *tok) { if (Token::Match(tok->tokAt(2), "void| )")) return 0; - int numpar = 1; - int parlevel = 0; + unsigned int numpar = 1; + unsigned int parlevel = 0; for (; tok; tok = tok->next()) { if (tok->str() == "(") ++parlevel; else if (tok->str() == ")") { - if (parlevel <= 1) + if (!parlevel) break; --parlevel; } - else if (parlevel == 1 && tok->str() == ",") { + else if (!parlevel && tok->str() == ",") { ++numpar; } } diff --git a/lib/checkinternal.cpp b/lib/checkinternal.cpp index 66b74cd88..a9e71d7a6 100644 --- a/lib/checkinternal.cpp +++ b/lib/checkinternal.cpp @@ -82,7 +82,7 @@ void CheckInternal::checkTokenSimpleMatchPatterns() // Check for [xyz] usage - but exclude standalone square brackets unsigned int char_count = 0; for (string::size_type pos = 0; pos < pattern.size(); ++pos) { - unsigned char c = pattern[pos]; + char c = pattern[pos]; if (c == ' ') { char_count = 0; @@ -99,7 +99,7 @@ void CheckInternal::checkTokenSimpleMatchPatterns() // Check | usage: Count characters before the symbol char_count = 0; for (string::size_type pos = 0; pos < pattern.size(); ++pos) { - unsigned char c = pattern[pos]; + char c = pattern[pos]; if (c == ' ') { char_count = 0; diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 1e5def01e..c9ff8dc38 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -1075,8 +1075,8 @@ void CheckStl::string_c_strError(const Token *tok) //--------------------------------------------------------------------------- void CheckStl::checkAutoPointer() { - std::set autoPtrVarId; - std::set::const_iterator iter; + std::set autoPtrVarId; + std::set::const_iterator iter; static const char STL_CONTAINER_LIST[] = "bitset|deque|list|map|multimap|multiset|priority_queue|queue|set|stack|hash_map|hash_multimap|hash_set|vector"; for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d606763c1..91841d3a4 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -956,7 +956,7 @@ void Tokenizer::simplifyTypedef() Token *argFuncRetEnd = 0; Token *funcStart = 0; Token *funcEnd = 0; - unsigned int offset = 1; + unsigned short offset = 1; bool function = false; bool functionPtr = false; bool functionRef = false; diff --git a/tools/dmake.cpp b/tools/dmake.cpp index d7d4479ce..91e495476 100644 --- a/tools/dmake.cpp +++ b/tools/dmake.cpp @@ -210,9 +210,10 @@ int main(int argc, char **argv) makeConditionalVariable(fout, "CXXFLAGS", "-O2 -DNDEBUG -Wall"); } else { // TODO: add more compiler warnings. - // -Wlogical-op : doesn't work on older GCC - // -Wconversion : too many warnings - // -Wsign-conversion : too many warnings + // -Wlogical-op : doesn't work on older GCC + // -Wconversion : too many warnings + // -Wsign-conversion : too many warnings + // -Wunreachable-code : some GCC versions report lots of warnings // The _GLIBCXX_DEBUG doesn't work in cygwin makeConditionalVariable(fout, "CXXFLAGS",