MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / valueFlowIteratorInfer

Function valueFlowIteratorInfer

lib/valueflow.cpp:6443–6473  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6441};
6442
6443static void valueFlowIteratorInfer(TokenList& tokenlist, const Settings& settings)
6444{
6445 for (Token* tok = tokenlist.front(); tok; tok = tok->next()) {
6446 if (!tok->scope())
6447 continue;
6448 if (!tok->scope()->isExecutable())
6449 continue;
6450 std::list<ValueFlow::Value> values = getIteratorValues(tok->values());
6451 values.remove_if([&](const ValueFlow::Value& v) {
6452 if (!v.isImpossible())
6453 return true;
6454 if (!v.condition)
6455 return true;
6456 if (v.bound != ValueFlow::Value::Bound::Point)
6457 return true;
6458 if (v.isIteratorEndValue() && v.intvalue <= 0)
6459 return true;
6460 if (v.isIteratorStartValue() && v.intvalue >= 0)
6461 return true;
6462 return false;
6463 });
6464 for (ValueFlow::Value& v : values) {
6465 v.setPossible();
6466 if (v.isIteratorStartValue())
6467 v.intvalue++;
6468 if (v.isIteratorEndValue())
6469 v.intvalue--;
6470 setTokenValue(tok, std::move(v), settings);
6471 }
6472 }
6473}
6474
6475static std::vector<ValueFlow::Value> getContainerValues(const Token* tok)
6476{

Callers 1

setValuesMethod · 0.85

Calls 6

getIteratorValuesFunction · 0.85
setTokenValueFunction · 0.85
frontMethod · 0.80
nextMethod · 0.80
scopeMethod · 0.80
isImpossibleMethod · 0.80

Tested by

no test coverage detected