From 6b124a37d8d94d96bd40acd23337f2521bd0babf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 28 Nov 2015 10:11:07 +0100 Subject: [PATCH] Cleanup some casts --- lib/checkbufferoverrun.cpp | 8 ++++---- lib/checkclass.cpp | 2 +- lib/checkstring.cpp | 4 ++-- lib/preprocessor.cpp | 4 ++-- lib/tokenize.cpp | 8 ++++---- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 715c5569c..1f10309f4 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -326,7 +326,7 @@ static bool checkMinSizes(const std::list &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 &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; } diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 70e593c21..21a1e779f 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -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(); diff --git a/lib/checkstring.cpp b/lib/checkstring.cpp index 85d62028b..0c4e794c3 100644 --- a/lib/checkstring.cpp +++ b/lib/checkstring.cpp @@ -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)); } } diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index dd2405ecb..506af7f46 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -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 } diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d5d117e4e..ba0b65584 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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); } }