Fix some GCC warnings regarding the sign conversion.

This commit is contained in:
Edoardo Prezioso 2011-10-30 18:34:49 +01:00
parent f7fe665b00
commit 433f4640a9
7 changed files with 19 additions and 17 deletions

View File

@ -26,6 +26,7 @@
#include <cstdlib> // EXIT_SUCCESS and EXIT_FAILURE #include <cstdlib> // EXIT_SUCCESS and EXIT_FAILURE
#include <cstring> #include <cstring>
#include <algorithm> #include <algorithm>
#include <climits>
#include "cmdlineparser.h" #include "cmdlineparser.h"
#include "filelister.h" #include "filelister.h"
@ -106,7 +107,7 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
bool warned = false; bool warned = false;
std::vector<std::string> ignored = parser.GetIgnoredPaths(); std::vector<std::string> ignored = parser.GetIgnoredPaths();
std::vector<std::string>::iterator iterIgnored = ignored.begin(); std::vector<std::string>::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]); const std::string extension = Path::getFilenameExtension(ignored[i]);
if (extension == ".h" || extension == ".hpp") { if (extension == ".h" || extension == ".hpp") {
ignored.erase(iterIgnored + i); ignored.erase(iterIgnored + i);
@ -120,14 +121,14 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
PathMatch matcher(parser.GetIgnoredPaths()); PathMatch matcher(parser.GetIgnoredPaths());
std::vector<std::string>::iterator iterBegin = filenames.begin(); std::vector<std::string>::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) #if defined(_WIN32)
// For Windows we want case-insensitive path matching // For Windows we want case-insensitive path matching
const bool caseSensitive = false; const bool caseSensitive = false;
#else #else
const bool caseSensitive = true; const bool caseSensitive = true;
#endif #endif
if (matcher.Match(filenames[(unsigned int)i], caseSensitive)) if (matcher.Match(filenames[i], caseSensitive))
filenames.erase(iterBegin + i); filenames.erase(iterBegin + i);
} }
} else { } else {

View File

@ -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) 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 std::string funcname = is_readlinkat ? "readlinkat" : "readlink";
const MathLib::bigint n = MathLib::toLongNumber(tok->strAt(6 + param_offset)); const MathLib::bigint n = MathLib::toLongNumber(tok->strAt(6 + param_offset));

View File

@ -1353,24 +1353,24 @@ bool CheckClass::isMemberVar(const Scope *scope, const Token *tok)
return false; return false;
} }
static int countParameters(const Token *tok) static unsigned int countParameters(const Token *tok)
{ {
if (Token::Match(tok->tokAt(2), "void| )")) if (Token::Match(tok->tokAt(2), "void| )"))
return 0; return 0;
int numpar = 1; unsigned int numpar = 1;
int parlevel = 0; unsigned int parlevel = 0;
for (; tok; tok = tok->next()) { for (; tok; tok = tok->next()) {
if (tok->str() == "(") if (tok->str() == "(")
++parlevel; ++parlevel;
else if (tok->str() == ")") { else if (tok->str() == ")") {
if (parlevel <= 1) if (!parlevel)
break; break;
--parlevel; --parlevel;
} }
else if (parlevel == 1 && tok->str() == ",") { else if (!parlevel && tok->str() == ",") {
++numpar; ++numpar;
} }
} }

View File

@ -82,7 +82,7 @@ void CheckInternal::checkTokenSimpleMatchPatterns()
// Check for [xyz] usage - but exclude standalone square brackets // Check for [xyz] usage - but exclude standalone square brackets
unsigned int char_count = 0; unsigned int char_count = 0;
for (string::size_type pos = 0; pos < pattern.size(); ++pos) { for (string::size_type pos = 0; pos < pattern.size(); ++pos) {
unsigned char c = pattern[pos]; char c = pattern[pos];
if (c == ' ') { if (c == ' ') {
char_count = 0; char_count = 0;
@ -99,7 +99,7 @@ void CheckInternal::checkTokenSimpleMatchPatterns()
// Check | usage: Count characters before the symbol // Check | usage: Count characters before the symbol
char_count = 0; char_count = 0;
for (string::size_type pos = 0; pos < pattern.size(); ++pos) { for (string::size_type pos = 0; pos < pattern.size(); ++pos) {
unsigned char c = pattern[pos]; char c = pattern[pos];
if (c == ' ') { if (c == ' ') {
char_count = 0; char_count = 0;

View File

@ -1075,8 +1075,8 @@ void CheckStl::string_c_strError(const Token *tok)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckStl::checkAutoPointer() void CheckStl::checkAutoPointer()
{ {
std::set<int> autoPtrVarId; std::set<unsigned int> autoPtrVarId;
std::set<int>::const_iterator iter; std::set<unsigned int>::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"; 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()) { for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {

View File

@ -956,7 +956,7 @@ void Tokenizer::simplifyTypedef()
Token *argFuncRetEnd = 0; Token *argFuncRetEnd = 0;
Token *funcStart = 0; Token *funcStart = 0;
Token *funcEnd = 0; Token *funcEnd = 0;
unsigned int offset = 1; unsigned short offset = 1;
bool function = false; bool function = false;
bool functionPtr = false; bool functionPtr = false;
bool functionRef = false; bool functionRef = false;

View File

@ -213,6 +213,7 @@ int main(int argc, char **argv)
// -Wlogical-op : doesn't work on older GCC // -Wlogical-op : doesn't work on older GCC
// -Wconversion : too many warnings // -Wconversion : too many warnings
// -Wsign-conversion : 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 // The _GLIBCXX_DEBUG doesn't work in cygwin
makeConditionalVariable(fout, "CXXFLAGS", makeConditionalVariable(fout, "CXXFLAGS",