Get rid of a compiler warning. conversion from 'size_t' to 'int', possible loss of data

This commit is contained in:
Reijo Tomperi 2009-10-10 22:54:58 +03:00
parent 237dcb9533
commit 4c8f7fa7fb
2 changed files with 10 additions and 10 deletions

View File

@ -123,7 +123,7 @@ void Tokenizer::addtoken(const char str[], const unsigned int lineno, const unsi
int Tokenizer::sizeOfType(const Token *type) const unsigned int Tokenizer::sizeOfType(const Token *type) const
{ {
if (!type || !type->strAt(0)) if (!type || !type->strAt(0))
return 0; return 0;
@ -1435,8 +1435,8 @@ void Tokenizer::simplifySizeof()
Token::Match(tok->tokAt(-2), "[;{}(,] %type% %var% [;),]") || Token::Match(tok->tokAt(-2), "[;{}(,] %type% %var% [;),]") ||
Token::Match(tok->tokAt(-3), "[;{}(,] const %type% %var% [;),]")) Token::Match(tok->tokAt(-3), "[;{}(,] const %type% %var% [;),]"))
{ {
const int size = sizeOfType(tok->previous()); const unsigned int size = sizeOfType(tok->previous());
if (size <= 0) if (size == 0)
{ {
continue; continue;
} }
@ -1447,8 +1447,8 @@ void Tokenizer::simplifySizeof()
else if (Token::Match(tok->tokAt(-1), "%type% %var% [ %num% ] [;=]") || else if (Token::Match(tok->tokAt(-1), "%type% %var% [ %num% ] [;=]") ||
Token::Match(tok->tokAt(-2), "%type% * %var% [ %num% ] [;=]")) Token::Match(tok->tokAt(-2), "%type% * %var% [ %num% ] [;=]"))
{ {
int size = sizeOfType(tok->tokAt(-1)); unsigned int size = sizeOfType(tok->tokAt(-1));
if (size <= 0) if (size == 0)
continue; continue;
sizeOfVar[varId] = MathLib::toString<long>(size * MathLib::toLongNumber(tok->strAt(2))); sizeOfVar[varId] = MathLib::toString<long>(size * MathLib::toLongNumber(tok->strAt(2)));
@ -1464,8 +1464,8 @@ void Tokenizer::simplifySizeof()
else if (Token::Match(tok->tokAt(-1), "%type% %var% [ ] = %str% ;")) else if (Token::Match(tok->tokAt(-1), "%type% %var% [ ] = %str% ;"))
{ {
int size = sizeOfType(tok->tokAt(4)); unsigned int size = sizeOfType(tok->tokAt(4));
if (size <= 0) if (size == 0)
continue; continue;
sizeOfVar[varId] = MathLib::toString<long>(size); sizeOfVar[varId] = MathLib::toString<long>(size);
@ -1574,7 +1574,7 @@ void Tokenizer::simplifySizeof()
else if (Token::Match(tok, "sizeof ( %type% )")) else if (Token::Match(tok, "sizeof ( %type% )"))
{ {
int size = sizeOfType(tok->tokAt(2)); unsigned int size = sizeOfType(tok->tokAt(2));
if (size > 0) if (size > 0)
{ {
tok->str(MathLib::toString<long>(size)); tok->str(MathLib::toString<long>(size));
@ -1585,7 +1585,7 @@ void Tokenizer::simplifySizeof()
else if (Token::Match(tok, "sizeof ( * %var% )") || Token::Match(tok, "sizeof ( %var% [ %num% ] )")) else if (Token::Match(tok, "sizeof ( * %var% )") || Token::Match(tok, "sizeof ( %var% [ %num% ] )"))
{ {
// Some default value.. // Some default value..
int sz = 100; unsigned int sz = 100;
unsigned int varid = tok->tokAt((tok->tokAt(2)->str() == "*") ? 3 : 2)->varId(); unsigned int varid = tok->tokAt((tok->tokAt(2)->str() == "*") ? 3 : 2)->varId();
if (varid != 0) if (varid != 0)

View File

@ -90,7 +90,7 @@ public:
* @param type Token which will contain e.g. "int", "*", or string. * @param type Token which will contain e.g. "int", "*", or string.
* @return sizeof for given type, or 0 if it can't be calculated. * @return sizeof for given type, or 0 if it can't be calculated.
*/ */
int sizeOfType(const Token *type) const; unsigned int sizeOfType(const Token *type) const;
const std::vector<std::string> *getFiles() const; const std::vector<std::string> *getFiles() const;