Refactoring: Use range for loops

This commit is contained in:
Daniel Marjamäki 2018-07-14 10:23:41 +02:00
parent c7b787888a
commit 449c48f6a7
1 changed files with 12 additions and 12 deletions

View File

@ -263,10 +263,10 @@ void CheckNullPointer::nullPointerLinkedList()
// if (tok->str() == "hello")
// tok = tok->next; // <- tok might become a null pointer!
// }
for (std::list<Scope>::const_iterator i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i) {
const Token* const tok1 = i->classDef;
for (const Scope &forScope : symbolDatabase->scopeList) {
const Token* const tok1 = forScope.classDef;
// search for a "for" scope..
if (i->type != Scope::eFor || !tok1)
if (forScope.type != Scope::eFor || !tok1)
continue;
// is there any dereferencing occurring in the for statement
@ -287,18 +287,18 @@ void CheckNullPointer::nullPointerLinkedList()
// Check usage of dereferenced variable in the loop..
// TODO: Move this to ValueFlow
for (const Scope *scope : i->nestedList) {
if (scope->type != Scope::eWhile)
for (const Scope *innerScope : forScope.nestedList) {
if (innerScope->type != Scope::eWhile)
continue;
// TODO: are there false negatives for "while ( %varid% ||"
if (Token::Match(scope->classDef->next(), "( %varid% &&|)", varid)) {
if (Token::Match(innerScope->classDef->next(), "( %varid% &&|)", varid)) {
// Make sure there is a "break" or "return" inside the loop.
// Without the "break" a null pointer could be dereferenced in the
// for statement.
for (const Token *tok4 = scope->bodyStart; tok4; tok4 = tok4->next()) {
if (tok4 == i->bodyEnd) {
const ValueFlow::Value v(scope->classDef, 0LL);
for (const Token *tok4 = innerScope->bodyStart; tok4; tok4 = tok4->next()) {
if (tok4 == forScope.bodyEnd) {
const ValueFlow::Value v(innerScope->classDef, 0LL);
nullPointerError(tok1, var->name(), &v, false);
break;
}
@ -418,9 +418,9 @@ void CheckNullPointer::nullConstantDereference()
parseFunctionCall(*tok, var, &mSettings->library);
// is one of the var items a NULL pointer?
for (std::list<const Token *>::const_iterator it = var.begin(); it != var.end(); ++it) {
if (Token::Match(*it, "0|NULL|nullptr [,)]")) {
nullPointerError(*it);
for (const Token *vartok : var) {
if (Token::Match(vartok, "0|NULL|nullptr [,)]")) {
nullPointerError(vartok);
}
}
}