Fix 10642: False positive: Possible dereference of an invalid iterator: v.begin()+v.size()-1 (#3630)
This commit is contained in:
parent
d2dd4e54b9
commit
6681576707
|
@ -7206,6 +7206,10 @@ static void valueFlowIteratorInfer(TokenList *tokenlist, const Settings *setting
|
|||
values.remove_if([&](const ValueFlow::Value& v) {
|
||||
if (!v.isImpossible())
|
||||
return true;
|
||||
if (!v.condition)
|
||||
return true;
|
||||
if (v.bound != ValueFlow::Value::Bound::Point)
|
||||
return true;
|
||||
if (v.isIteratorEndValue() && v.intvalue <= 0)
|
||||
return true;
|
||||
if (v.isIteratorStartValue() && v.intvalue >= 0)
|
||||
|
|
|
@ -4200,6 +4200,12 @@ private:
|
|||
ASSERT_EQUALS(
|
||||
"[test.cpp:4] -> [test.cpp:4]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1.\n",
|
||||
errout.str());
|
||||
|
||||
// #10642
|
||||
check("int f(std::vector<int> v) {\n"
|
||||
" return *(v.begin() + v.size() - 1);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void dereferenceInvalidIterator2() {
|
||||
|
|
Loading…
Reference in New Issue