diff --git a/lib/vf_iterators.cpp b/lib/vf_iterators.cpp index 1f85a27873a..6e813c19bf8 100644 --- a/lib/vf_iterators.cpp +++ b/lib/vf_iterators.cpp @@ -31,17 +31,17 @@ namespace ValueFlow { - static Library::Container::Yield findIteratorYield(Token* tok, const Token** ftok, const Settings &settings) + static Library::Container::Yield findIteratorYield(Token* tok, const Token*& ftok, const Settings &settings) { - auto yield = astContainerYield(tok, ftok); - if (ftok && *ftok) + auto yield = astContainerYield(tok, &ftok); + if (ftok) return yield; if (!tok->astParent()) return yield; //begin/end free functions - return astFunctionYield(tok->astParent()->previous(), settings, ftok); + return astFunctionYield(tok->astParent()->previous(), settings, &ftok); } void analyzeIterators(TokenList &tokenlist, const Settings &settings) @@ -53,18 +53,18 @@ namespace ValueFlow continue; if (!astIsContainer(tok)) continue; - Token* ftok = nullptr; - const Library::Container::Yield yield = findIteratorYield(tok, const_cast(&ftok), settings); - if (ftok) { - Value v(0); - v.setKnown(); - if (yield == Library::Container::Yield::START_ITERATOR) { - v.valueType = Value::ValueType::ITERATOR_START; - setTokenValue(ftok->next(), std::move(v), settings); - } else if (yield == Library::Container::Yield::END_ITERATOR) { - v.valueType = Value::ValueType::ITERATOR_END; - setTokenValue(ftok->next(), std::move(v), settings); - } + const Token* ftok = nullptr; + const Library::Container::Yield yield = findIteratorYield(tok, ftok, settings); + if (!ftok) + continue; + Value v(0); + v.setKnown(); + if (yield == Library::Container::Yield::START_ITERATOR) { + v.valueType = Value::ValueType::ITERATOR_START; + setTokenValue(const_cast(ftok)->next(), std::move(v), settings); + } else if (yield == Library::Container::Yield::END_ITERATOR) { + v.valueType = Value::ValueType::ITERATOR_END; + setTokenValue(const_cast(ftok)->next(), std::move(v), settings); } } } diff --git a/lib/vf_settokenvalue.cpp b/lib/vf_settokenvalue.cpp index b6c4ac255d8..4ddf9d356df 100644 --- a/lib/vf_settokenvalue.cpp +++ b/lib/vf_settokenvalue.cpp @@ -46,18 +46,16 @@ namespace ValueFlow { - static Library::Container::Yield getContainerYield(Token* tok, const Settings& settings, Token** parent = nullptr) + static Library::Container::Yield getContainerYield(Token* tok, const Settings& settings, Token*& parent) { if (Token::Match(tok, ". %name% (") && tok->astParent() == tok->tokAt(2) && tok->astOperand1() && tok->astOperand1()->valueType()) { const Library::Container* c = getLibraryContainer(tok->astOperand1()); - if (parent) - *parent = tok->astParent(); + parent = tok->astParent(); return c ? c->getYield(tok->strAt(1)) : Library::Container::Yield::NO_YIELD; } if (Token::Match(tok->previous(), "%name% (")) { - if (parent) - *parent = tok; + parent = tok; if (const Library::Function* f = settings.library.getFunction(tok->previous())) { return f->containerYield; } @@ -302,7 +300,7 @@ namespace ValueFlow } } Token* next = nullptr; - const Library::Container::Yield yields = getContainerYield(parent, settings, &next); + const Library::Container::Yield yields = getContainerYield(parent, settings, next); if (yields == Library::Container::Yield::SIZE) { Value v(value); v.valueType = Value::ValueType::INT;