Cleanup some casts

This commit is contained in:
Daniel Marjamäki 2015-11-28 10:11:07 +01:00
parent 5d1307814b
commit 6b124a37d8
5 changed files with 13 additions and 13 deletions

View File

@ -326,7 +326,7 @@ static bool checkMinSizes(const std::list<Library::ArgumentChecks::MinSize> &min
case Library::ArgumentChecks::MinSize::ARGVALUE:
if (Token::Match(argtok, "%num% ,|)")) {
const MathLib::bigint sz = MathLib::toLongNumber(argtok->str());
if ((std::size_t)sz > arraySize)
if (sz > arraySize)
error = true;
} else if (argtok->tokType() == Token::eChar && Token::Match(argtok->next(), ",|)") && charSizeToken)
*charSizeToken = argtok; //sizeArgumentAsCharError(argtok);
@ -335,7 +335,7 @@ static bool checkMinSizes(const std::list<Library::ArgumentChecks::MinSize> &min
// TODO: handle arbitrary arg2
if (minsize->arg2 == minsize->arg+1 && Token::Match(argtok, "%num% , %num% ,|)")) {
const MathLib::bigint sz = MathLib::toLongNumber(argtok->str()) * MathLib::toLongNumber(argtok->strAt(2));
if ((std::size_t)sz > arraySize)
if (sz > arraySize)
error = true;
}
break;
@ -388,7 +388,7 @@ void CheckBufferOverrun::checkFunctionParameter(const Token &ftok, unsigned int
return;
const Token *charSizeToken = nullptr;
if (checkMinSizes(*minsizes, &ftok, (std::size_t)arraySize, &charSizeToken, _settings))
if (checkMinSizes(*minsizes, &ftok, arraySize, &charSizeToken, _settings))
bufferOverrunError(callstack, arrayInfo.varname());
if (charSizeToken)
sizeArgumentAsCharError(charSizeToken);
@ -1567,7 +1567,7 @@ MathLib::biguint CheckBufferOverrun::countSprintfLength(const std::string &input
}
}
return (MathLib::biguint)input_string_size;
return input_string_size;
}

View File

@ -1035,7 +1035,7 @@ void CheckClass::checkMemset()
}
if (var->isArray())
numIndirToVariableType += (int)var->dimensions().size();
numIndirToVariableType += var->dimensions().size();
if (numIndirToVariableType == 1)
type = var->typeScope();

View File

@ -281,12 +281,12 @@ void CheckString::checkIncorrectStringCompare()
const Token* end = tok->linkAt(2)->next();
if (Token::Match(begin->previous(), "%str% ==|!=") && begin->strAt(-2) != "+") {
std::size_t slen = Token::getStrLength(begin->previous());
if (clen != (int)slen) {
if (clen != slen) {
incorrectStringCompareError(tok->next(), "substr", begin->strAt(-1));
}
} else if (Token::Match(end, "==|!= %str% !!+")) {
std::size_t slen = Token::getStrLength(end->next());
if (clen != (int)slen) {
if (clen != slen) {
incorrectStringCompareError(tok->next(), "substr", end->strAt(1));
}
}

View File

@ -174,9 +174,9 @@ std::string Preprocessor::read(std::istream &istr, const std::string &filename)
// The UTF-16 BOM is 0xfffe or 0xfeff.
unsigned int bom = 0;
if (istr.peek() >= 0xfe) {
bom = ((unsigned int)istr.get() << 8);
bom = ((unsigned char)istr.get() << 8);
if (istr.peek() >= 0xfe)
bom |= (unsigned int)istr.get();
bom |= (unsigned char)istr.get();
else
bom = 0; // allowed boms are 0/0xfffe/0xfeff
}

View File

@ -2183,7 +2183,7 @@ void Tokenizer::arraySize()
if (addlength || Token::Match(tok, "%var% [ ] = %str% ;")) {
tok = tok->next();
std::size_t sz = Token::getStrSize(tok->tokAt(3));
tok->insertToken(MathLib::toString((unsigned int)sz));
tok->insertToken(MathLib::toString(sz));
tok = tok->tokAt(5);
}
@ -2195,7 +2195,7 @@ void Tokenizer::arraySize()
if (tok2->link() && Token::Match(tok2, "{|(|[|<")) {
if (tok2->str() == "[" && tok2->link()->strAt(1) == "=") { // designated initializer
if (Token::Match(tok2, "[ %num% ]"))
sz = std::max(sz, (unsigned int)MathLib::toULongNumber(tok2->strAt(1)) + 1U);
sz = std::max(sz, MathLib::toULongNumber(tok2->strAt(1)) + 1U);
else {
sz = 0;
break;
@ -7095,8 +7095,8 @@ void Tokenizer::simplifyCharAt()
if (Token::Match(tok, "%str% [ %num% ]")) {
const MathLib::bigint index = MathLib::toLongNumber(tok->strAt(2));
// Check within range
if (index >= 0 && index <= (MathLib::bigint)Token::getStrLength(tok)) {
tok->str("'" + Token::getCharAt(tok, (size_t)index) + "'");
if (index >= 0 && index <= Token::getStrLength(tok)) {
tok->str("'" + Token::getCharAt(tok, index) + "'");
tok->deleteNext(3);
}
}