Refactoring: Use range for loops
This commit is contained in:
parent
eeda082a2f
commit
7dda8e2a2d
|
@ -62,9 +62,7 @@ void CheckIO::checkCoutCerrMisusage()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const SymbolDatabase * const symbolDatabase = mTokenizer->getSymbolDatabase();
|
const SymbolDatabase * const symbolDatabase = mTokenizer->getSymbolDatabase();
|
||||||
const std::size_t functions = symbolDatabase->functionScopes.size();
|
for (const Scope * scope : symbolDatabase->functionScopes) {
|
||||||
for (std::size_t i = 0; i < functions; ++i) {
|
|
||||||
const Scope * scope = symbolDatabase->functionScopes[i];
|
|
||||||
for (const Token *tok = scope->bodyStart; tok && tok != scope->bodyEnd; tok = tok->next()) {
|
for (const Token *tok = scope->bodyStart; tok && tok != scope->bodyEnd; tok = tok->next()) {
|
||||||
if (Token::Match(tok, "std :: cout|cerr !!.") && tok->next()->astParent() && tok->next()->astParent()->astOperand1() == tok->next()) {
|
if (Token::Match(tok, "std :: cout|cerr !!.") && tok->next()->astParent() && tok->next()->astParent()->astOperand1() == tok->next()) {
|
||||||
const Token* tok2 = tok->next();
|
const Token* tok2 = tok->next();
|
||||||
|
@ -382,9 +380,7 @@ void CheckIO::invalidScanf()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const SymbolDatabase * const symbolDatabase = mTokenizer->getSymbolDatabase();
|
const SymbolDatabase * const symbolDatabase = mTokenizer->getSymbolDatabase();
|
||||||
const std::size_t functions = symbolDatabase->functionScopes.size();
|
for (const Scope * scope : symbolDatabase->functionScopes) {
|
||||||
for (std::size_t j = 0; j < functions; ++j) {
|
|
||||||
const Scope * scope = symbolDatabase->functionScopes[j];
|
|
||||||
for (const Token *tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
|
for (const Token *tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
|
||||||
const Token *formatToken = nullptr;
|
const Token *formatToken = nullptr;
|
||||||
if (Token::Match(tok, "scanf|vscanf ( %str% ,"))
|
if (Token::Match(tok, "scanf|vscanf ( %str% ,"))
|
||||||
|
@ -497,9 +493,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
|
||||||
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
|
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
|
||||||
const bool isWindows = mSettings->isWindowsPlatform();
|
const bool isWindows = mSettings->isWindowsPlatform();
|
||||||
|
|
||||||
const std::size_t functions = symbolDatabase->functionScopes.size();
|
for (const Scope * scope : symbolDatabase->functionScopes) {
|
||||||
for (std::size_t j = 0; j < functions; ++j) {
|
|
||||||
const Scope * scope = symbolDatabase->functionScopes[j];
|
|
||||||
for (const Token *tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
|
for (const Token *tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
|
||||||
if (!tok->isName()) continue;
|
if (!tok->isName()) continue;
|
||||||
|
|
||||||
|
@ -1294,9 +1288,9 @@ void CheckIO::checkFormatString(const Token * const tok,
|
||||||
|
|
||||||
if (printWarning) {
|
if (printWarning) {
|
||||||
// Check that all parameter positions reference an actual parameter
|
// Check that all parameter positions reference an actual parameter
|
||||||
for (std::set<unsigned int>::const_iterator it = parameterPositionsUsed.begin() ; it != parameterPositionsUsed.end() ; ++it) {
|
for (unsigned int i : parameterPositionsUsed) {
|
||||||
if ((*it == 0) || (*it > numFormat))
|
if ((i == 0) || (i > numFormat))
|
||||||
wrongPrintfScanfPosixParameterPositionError(tok, tok->str(), *it, numFormat);
|
wrongPrintfScanfPosixParameterPositionError(tok, tok->str(), i, numFormat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1584,11 +1578,10 @@ bool CheckIO::ArgumentInfo::isStdVectorOrString()
|
||||||
} else if (variableInfo->type()) {
|
} else if (variableInfo->type()) {
|
||||||
const Scope * classScope = variableInfo->type()->classScope;
|
const Scope * classScope = variableInfo->type()->classScope;
|
||||||
if (classScope) {
|
if (classScope) {
|
||||||
for (std::list<Function>::const_iterator functions = classScope->functionList.begin();
|
for (const Function &func : classScope->functionList) {
|
||||||
functions != classScope->functionList.end(); ++functions) {
|
if (func.name() == "operator[]") {
|
||||||
if (functions->name() == "operator[]") {
|
if (Token::Match(func.retDef, "%type% &")) {
|
||||||
if (Token::Match(functions->retDef, "%type% &")) {
|
typeToken = func.retDef;
|
||||||
typeToken = functions->retDef;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1599,15 +1592,13 @@ bool CheckIO::ArgumentInfo::isStdVectorOrString()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
static const std::set<std::string> stl_container = {
|
||||||
const std::set<std::string> stl_container = {
|
|
||||||
"array", "bitset", "deque", "forward_list",
|
"array", "bitset", "deque", "forward_list",
|
||||||
"hash_map", "hash_multimap", "hash_set",
|
"hash_map", "hash_multimap", "hash_set",
|
||||||
"list", "map", "multimap", "multiset",
|
"list", "map", "multimap", "multiset",
|
||||||
"priority_queue", "queue", "set", "stack",
|
"priority_queue", "queue", "set", "stack",
|
||||||
"unordered_map", "unordered_multimap", "unordered_multiset", "unordered_set", "vector"
|
"unordered_map", "unordered_multimap", "unordered_multiset", "unordered_set", "vector"
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
bool CheckIO::ArgumentInfo::isStdContainer(const Token *tok)
|
bool CheckIO::ArgumentInfo::isStdContainer(const Token *tok)
|
||||||
{
|
{
|
||||||
|
@ -1622,9 +1613,8 @@ bool CheckIO::ArgumentInfo::isStdContainer(const Token *tok)
|
||||||
typeToken = variable->typeStartToken();
|
typeToken = variable->typeStartToken();
|
||||||
return true;
|
return true;
|
||||||
} else if (variable->type() && !variable->type()->derivedFrom.empty()) {
|
} else if (variable->type() && !variable->type()->derivedFrom.empty()) {
|
||||||
const std::vector<Type::BaseInfo>& derivedFrom = variable->type()->derivedFrom;
|
for (const Type::BaseInfo &baseInfo : variable->type()->derivedFrom) {
|
||||||
for (std::size_t i = 0, size = derivedFrom.size(); i < size; ++i) {
|
const Token* nameTok = baseInfo.nameTok;
|
||||||
const Token* nameTok = derivedFrom[i].nameTok;
|
|
||||||
if (Token::Match(nameTok, "std :: vector|array|bitset|deque|list|forward_list|map|multimap|multiset|priority_queue|queue|set|stack|hash_map|hash_multimap|hash_set|unordered_map|unordered_multimap|unordered_set|unordered_multiset <")) {
|
if (Token::Match(nameTok, "std :: vector|array|bitset|deque|list|forward_list|map|multimap|multiset|priority_queue|queue|set|stack|hash_map|hash_multimap|hash_set|unordered_map|unordered_multimap|unordered_set|unordered_multiset <")) {
|
||||||
typeToken = nameTok->tokAt(4);
|
typeToken = nameTok->tokAt(4);
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue