diff --git a/lib/token.cpp b/lib/token.cpp index 20bf8fa19..d3210bd8c 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -552,7 +552,7 @@ bool Token::simpleMatch(const Token *tok, const char pattern[]) next = pattern + std::strlen(pattern); while (*current) { - std::size_t length = static_cast(next - current); + std::size_t length = next - current; if (!tok || length != tok->_str.length() || std::strncmp(current, tok->_str.c_str(), length)) return false; @@ -1043,16 +1043,16 @@ std::string Token::stringifyList(bool varid, bool attributes, bool linenumbers, std::ostringstream ret; unsigned int lineNumber = _linenr; - int fileInd = files ? -1 : static_cast(_fileIndex); + unsigned int fileInd = files ? ~0U : _fileIndex; std::map lineNumbers; for (const Token *tok = this; tok != end; tok = tok->next()) { bool fileChange = false; - if (static_cast(tok->_fileIndex) != fileInd) { - if (fileInd != -1) { + if (tok->_fileIndex != fileInd) { + if (fileInd != ~0U) { lineNumbers[fileInd] = tok->_fileIndex; } - fileInd = static_cast(tok->_fileIndex); + fileInd = tok->_fileIndex; if (files) { ret << "\n\n##file "; if (fileNames && fileNames->size() > tok->_fileIndex) @@ -1066,7 +1066,7 @@ std::string Token::stringifyList(bool varid, bool attributes, bool linenumbers, } if (linebreaks && (lineNumber != tok->linenr() || fileChange)) { - if (lineNumber+4 < tok->linenr() && fileInd == static_cast(tok->_fileIndex)) { + if (lineNumber+4 < tok->linenr() && fileInd == tok->_fileIndex) { ret << '\n' << lineNumber+1 << ":\n|\n"; ret << tok->linenr()-1 << ":\n"; ret << tok->linenr() << ": "; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 97b365026..034a99b6d 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -135,7 +135,7 @@ unsigned int Tokenizer::sizeOfType(const Token *type) const return 0; if (type->tokType() == Token::eString) - return static_cast(Token::getStrLength(type) + 1); + return Token::getStrLength(type) + 1U; std::map::const_iterator it = _typeSize.find(type->str()); if (it == _typeSize.end()) @@ -3052,7 +3052,7 @@ bool Tokenizer::simplifySizeof() Token* tok2 = tok->next(); do { - size *= static_cast(MathLib::toLongNumber(tok2->strAt(1))); + size *= MathLib::toULongNumber(tok2->strAt(1)); tok2 = tok2->tokAt(3); } while (Token::Match(tok2, "[ %num% ]")); if (Token::Match(tok2, "[;=]")) { @@ -3183,7 +3183,7 @@ bool Tokenizer::simplifySizeof() for (unsigned int i = 0; i < derefs; i++) tok2 = tok2->linkAt(1); // Skip all dimensions that are derefenced before the sizeof call while (Token::Match(tok2, "] [ %num% ]")) { - sz *= static_cast(MathLib::toULongNumber(tok2->strAt(2))); + sz *= MathLib::toULongNumber(tok2->strAt(2)); tok2 = tok2->linkAt(1); } if (Token::simpleMatch(tok2, "] [")) @@ -3195,7 +3195,7 @@ bool Tokenizer::simplifySizeof() continue; const Token *tok2 = nametok->next(); while (Token::Match(tok2, "[ %num% ]")) { - sz *= static_cast(MathLib::toLongNumber(tok2->strAt(1))); + sz *= MathLib::toULongNumber(tok2->strAt(1)); tok2 = tok2->link()->next(); } if (!tok2 || tok2->str() != ")") diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 0c66c5e16..cf2e7c822 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -92,7 +92,7 @@ unsigned int TokenList::appendFileIfNew(const std::string &fileName) _isCPP = _settings->enforcedLang == Settings::CPP || (_settings->enforcedLang == Settings::None && Path::isCPP(getSourceFilePath())); } } - return static_cast(_files.size() - 1); + return _files.size() - 1U; } void TokenList::deleteTokens(Token *tok) @@ -400,7 +400,7 @@ unsigned long long TokenList::calculateChecksum() const { unsigned long long checksum = 0; for (const Token* tok = front(); tok; tok = tok->next()) { - const unsigned int subchecksum1 = tok->flags() + tok->varId() + static_cast(tok->tokType()); + const unsigned int subchecksum1 = tok->flags() + tok->varId() + tok->tokType(); unsigned int subchecksum2 = 0; for (std::size_t i = 0; i < tok->str().size(); i++) subchecksum2 += (unsigned int)tok->str()[i];