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

Function getOOBIterValue

lib/checkstl.cpp:3340–3356  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3338}
3339
3340static const ValueFlow::Value* getOOBIterValue(const Token* tok, const ValueFlow::Value* sizeVal)
3341{
3342 auto it = std::find_if(tok->values().begin(), tok->values().end(), [&](const ValueFlow::Value& v) {
3343 if (v.isPossible() || v.isKnown()) {
3344 switch (v.valueType) {
3345 case ValueFlow::Value::ValueType::ITERATOR_END:
3346 return v.intvalue >= 0;
3347 case ValueFlow::Value::ValueType::ITERATOR_START:
3348 return (v.intvalue < 0) || (sizeVal && v.intvalue >= sizeVal->intvalue);
3349 default:
3350 break;
3351 }
3352 }
3353 return false;
3354 });
3355 return it != tok->values().end() ? &*it : nullptr;
3356}
3357
3358void CheckStlImpl::eraseIteratorOutOfBounds()
3359{

Callers 1

Calls 4

isPossibleMethod · 0.80
isKnownMethod · 0.80
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected