CheckStl: Safer use of AST

This commit is contained in:
Daniel Marjamäki 2017-07-26 23:43:39 +02:00
parent d13a8d6a32
commit 27af3edc5b
1 changed files with 1 additions and 2 deletions

3
lib/checkstl.cpp Normal file → Executable file
View File

@ -140,13 +140,12 @@ void CheckStl::iterators()
validIterator = true;
// Is iterator compared against different container?
if (tok2->isComparisonOp() && container) {
if (tok2->isComparisonOp() && container && tok2->astOperand1() && tok2->astOperand2()) {
const Token *other = nullptr;
if (tok2->astOperand1()->varId() == iteratorId)
other = tok2->astOperand2()->tokAt(-3);
else if (tok2->astOperand2()->varId() == iteratorId)
other = tok2->astOperand1()->tokAt(-3);
if (Token::Match(other, "%name% . end|rend|cend|crend ( )") && other->varId() != container->declarationId())
iteratorsError(tok2, container->name(), other->str());
}