Skip to content

Commit 2d4f640

Browse files
committed
Refactoring: Use continue in loop
1 parent 2f38d3d commit 2d4f640

1 file changed

Lines changed: 27 additions & 28 deletions

File tree

lib/checkstl.cpp

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -386,41 +386,40 @@ void CheckStl::stlOutOfBounds()
386386
tok = tok->next();
387387

388388
// check if the for loop condition is wrong
389-
if (Token::Match(tok, "%var% <= %var% . %name% ( ) ;|)|%oror%")) {
390-
// Is it a vector?
391-
const Variable *var = tok->tokAt(2)->variable();
392-
if (!var)
393-
continue;
389+
if (!Token::Match(tok, "%var% <= %var% . %name% ( ) ;|)|%oror%"))
390+
continue;
391+
// Is it a vector?
392+
const Variable *var = tok->tokAt(2)->variable();
393+
if (!var)
394+
continue;
394395

395-
const Library::Container* container = _settings->library.detectContainer(var->typeStartToken());
396-
if (!container)
397-
continue;
396+
const Library::Container* container = _settings->library.detectContainer(var->typeStartToken());
397+
if (!container)
398+
continue;
398399

399-
if (container->getYield(tok->strAt(4)) != Library::Container::SIZE)
400-
continue;
400+
if (container->getYield(tok->strAt(4)) != Library::Container::SIZE)
401+
continue;
401402

402-
// variable id for loop variable.
403-
const unsigned int numId = tok->varId();
403+
// variable id for loop variable.
404+
const unsigned int numId = tok->varId();
404405

405-
// variable id for the container variable
406-
const unsigned int declarationId = var->declarationId();
406+
// variable id for the container variable
407+
const unsigned int declarationId = var->declarationId();
407408

408-
for (const Token *tok3 = i->classStart; tok3 && tok3 != i->classEnd; tok3 = tok3->next()) {
409-
if (tok3->varId() == declarationId) {
410-
tok3 = tok3->next();
411-
if (Token::Match(tok3, ". %name% ( )")) {
412-
if (container->getYield(tok3->strAt(1)) == Library::Container::SIZE)
413-
break;
414-
} else if (container->arrayLike_indexOp && Token::Match(tok3, "[ %varid% ]", numId))
415-
stlOutOfBoundsError(tok3, tok3->strAt(1), var->name(), false);
416-
else if (Token::Match(tok3, ". %name% ( %varid% )", numId)) {
417-
Library::Container::Yield yield = container->getYield(tok3->strAt(1));
418-
if (yield == Library::Container::AT_INDEX)
419-
stlOutOfBoundsError(tok3, tok3->strAt(3), var->name(), true);
420-
}
409+
for (const Token *tok3 = i->classStart; tok3 && tok3 != i->classEnd; tok3 = tok3->next()) {
410+
if (tok3->varId() == declarationId) {
411+
tok3 = tok3->next();
412+
if (Token::Match(tok3, ". %name% ( )")) {
413+
if (container->getYield(tok3->strAt(1)) == Library::Container::SIZE)
414+
break;
415+
} else if (container->arrayLike_indexOp && Token::Match(tok3, "[ %varid% ]", numId))
416+
stlOutOfBoundsError(tok3, tok3->strAt(1), var->name(), false);
417+
else if (Token::Match(tok3, ". %name% ( %varid% )", numId)) {
418+
Library::Container::Yield yield = container->getYield(tok3->strAt(1));
419+
if (yield == Library::Container::AT_INDEX)
420+
stlOutOfBoundsError(tok3, tok3->strAt(3), var->name(), true);
421421
}
422422
}
423-
continue;
424423
}
425424
}
426425
}

0 commit comments

Comments
 (0)