From 9d9a5b0623903066524a9387e99f710f65550e54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 21 Nov 2010 11:48:27 +0100 Subject: [PATCH] VS: Fixed compiler warnings. Ticket: #2200 --- lib/checkbufferoverrun.cpp | 28 ++++++++++++++-------------- lib/checkbufferoverrun.h | 9 +++++---- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 47664e66c..b0d168a6d 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -46,7 +46,7 @@ CheckBufferOverrun instance; //--------------------------------------------------------------------------- -void CheckBufferOverrun::arrayIndexOutOfBounds(const Token *tok, int size, int index) +void CheckBufferOverrun::arrayIndexOutOfBounds(const Token *tok, MathLib::bigint size, MathLib::bigint index) { if (size >= 1) { @@ -598,7 +598,7 @@ void CheckBufferOverrun::checkFunctionCall(const Token &tok, unsigned int par, c if (Token::Match(ftok->previous(), "[=+-*/;{}] %var% [ %num% ]")) { - long index = MathLib::toLongNumber(ftok->strAt(2)); + const MathLib::bigint index = MathLib::toLongNumber(ftok->strAt(2)); if (index >= 0 && arrayInfo.num[0] > 0 && static_cast(index) >= arrayInfo.num[0]) { std::list callstack; @@ -619,7 +619,7 @@ void CheckBufferOverrun::checkFunctionCall(const Token &tok, unsigned int par, c -void CheckBufferOverrun::checkScope(const Token *tok, const std::vector &varname, const int size, const int total_size, unsigned int varid) +void CheckBufferOverrun::checkScope(const Token *tok, const std::vector &varname, const MathLib::bigint size, const MathLib::bigint total_size, unsigned int varid) { std::string varnames; for (unsigned int i = 0; i < varname.size(); ++i) @@ -639,7 +639,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vectorstrAt(2)); + const MathLib::bigint index = MathLib::toLongNumber(tok->strAt(2)); if (index >= size) { arrayIndexOutOfBounds(tok, size, index); @@ -648,7 +648,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vectorstrAt(2 + varc)); + const MathLib::bigint index = MathLib::toLongNumber(tok->strAt(2 + varc)); if (index >= size) { arrayIndexOutOfBounds(tok->tokAt(varc), size, index); @@ -681,7 +681,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vectorisName() && !Token::Match(tok, "[.&]") && Token::Match(tok->next(), "%varid% [ %num% ]", varid)) { - int index = MathLib::toLongNumber(tok->strAt(3)); + const MathLib::bigint index = MathLib::toLongNumber(tok->strAt(3)); if (index < 0 || index >= size) { if (index > size || !Token::Match(tok->previous(), "& (")) @@ -692,7 +692,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vectorstrAt(3)); + const MathLib::bigint index = MathLib::toLongNumber(tok->strAt(3)); if (index < 0 || index >= size) { arrayIndexOutOfBounds(tok->next(), size, index); @@ -701,7 +701,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vectorisName() && !Token::Match(tok, "[.&]") && Token::Match(tok->next(), (varnames + " [ %num% ]").c_str())) { - int index = MathLib::toLongNumber(tok->strAt(3 + varc)); + const MathLib::bigint index = MathLib::toLongNumber(tok->strAt(3 + varc)); if (index >= size) { arrayIndexOutOfBounds(tok->tokAt(1 + varc), size, index); @@ -1081,7 +1081,7 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable() else if (tok->str() == "}") --indentlevel; - int size = 0; + MathLib::bigint size = 0; std::string type; unsigned int varid = 0; int nextTok = 0; @@ -1226,7 +1226,7 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable() Token sizeTok(0); sizeTok.str(type); - int total_size = size * static_cast(_tokenizer->sizeOfType(&sizeTok)); + const MathLib::bigint total_size = size * static_cast(_tokenizer->sizeOfType(&sizeTok)); if (total_size == 0) continue; @@ -1717,7 +1717,7 @@ void CheckBufferOverrun::checkInsecureCmdLineArgs() //--------------------------------------------------------------------------- -void CheckBufferOverrun::negativeIndexError(const Token *tok, long index) +void CheckBufferOverrun::negativeIndexError(const Token *tok, MathLib::bigint index) { std::ostringstream ostr; ostr << "Array index " << index << " is out of bounds"; @@ -1729,7 +1729,7 @@ void CheckBufferOverrun::negativeIndex() const char pattern[] = "[ %num% ]"; for (const Token *tok = Token::findmatch(_tokenizer->tokens(), pattern); tok; tok = Token::findmatch(tok->next(),pattern)) { - const long index = MathLib::toLongNumber(tok->next()->str()); + const MathLib::bigint index = MathLib::toLongNumber(tok->next()->str()); if (index < 0) { // Negative index. Check if it's an array. @@ -1797,9 +1797,9 @@ CheckBufferOverrun::ArrayInfo::ArrayInfo(unsigned int id, const std::string &nam _varname = name; } -CheckBufferOverrun::ArrayInfo CheckBufferOverrun::ArrayInfo::limit(long value) const +CheckBufferOverrun::ArrayInfo CheckBufferOverrun::ArrayInfo::limit(MathLib::bigint value) const { - unsigned long uvalue = (unsigned long)std::max(0L, value); + unsigned long uvalue = (unsigned long)std::max(MathLib::bigint(0), value); unsigned int n = 1; for (unsigned int i = 0; i < num.size(); ++i) n *= num[i]; diff --git a/lib/checkbufferoverrun.h b/lib/checkbufferoverrun.h index 650c43b41..7ba954f65 100644 --- a/lib/checkbufferoverrun.h +++ b/lib/checkbufferoverrun.h @@ -24,6 +24,7 @@ #include "check.h" #include "settings.h" +#include "mathlib.h" #include #include #include @@ -105,7 +106,7 @@ public: void negativeIndex(); /** Check for buffer overruns */ - void checkScope(const Token *tok, const std::vector &varname, const int size, const int total_size, unsigned int varid); + void checkScope(const Token *tok, const std::vector &varname, const MathLib::bigint size, const MathLib::bigint total_size, unsigned int varid); /** Information about N-dimensional array */ class ArrayInfo @@ -137,7 +138,7 @@ public: ArrayInfo(unsigned int id, const std::string &name, unsigned int size1, unsigned int n); /** Create a copy ArrayInfo where the number of elements have been limited by a value */ - ArrayInfo limit(long value) const; + ArrayInfo limit(MathLib::bigint value) const; /** * Declare array - set info @@ -175,7 +176,7 @@ public: */ void checkFunctionCall(const Token &tok, const unsigned int par, const ArrayInfo &arrayInfo); - void arrayIndexOutOfBounds(const Token *tok, int size, int index); + void arrayIndexOutOfBounds(const Token *tok, MathLib::bigint size, MathLib::bigint index); void arrayIndexOutOfBounds(const Token *tok, const ArrayInfo &arrayInfo, const std::vector &index); void arrayIndexOutOfBounds(const std::list &callstack, const ArrayInfo &arrayInfo, const std::vector &index); void bufferOverrun(const Token *tok, const std::string &varnames = ""); @@ -183,7 +184,7 @@ public: void outOfBounds(const Token *tok, const std::string &what); void sizeArgumentAsChar(const Token *tok); void terminateStrncpyError(const Token *tok); - void negativeIndexError(const Token *tok, long index); + void negativeIndexError(const Token *tok, MathLib::bigint index); void cmdLineArgsError(const Token *tok); void getErrorMessages()