Fix 10657: False positive; ValueFlow - invalid iterator (#3636)
This commit is contained in:
parent
ac4f4258a0
commit
398fa28021
|
@ -7188,7 +7188,7 @@ struct IteratorConditionHandler : SimpleConditionHandler {
|
|||
if (!values.empty()) {
|
||||
cond.vartok = tok->astOperand2();
|
||||
} else {
|
||||
values = getIteratorValues(tok->astOperand2()->values());
|
||||
values = getIteratorValues(tok->astOperand2()->values(), &kind);
|
||||
if (!values.empty())
|
||||
cond.vartok = tok->astOperand1();
|
||||
}
|
||||
|
|
|
@ -4201,6 +4201,20 @@ private:
|
|||
"[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());
|
||||
|
||||
// #10657
|
||||
check("std::list<int> mValues;\n"
|
||||
"typedef std::list<int>::iterator ValueIterator;\n"
|
||||
"void foo(ValueIterator beginValue, ValueIterator endValue) {\n"
|
||||
" ValueIterator prevValue = beginValue;\n"
|
||||
" ValueIterator curValue = beginValue;\n"
|
||||
" for (++curValue; prevValue != endValue && curValue != mValues.end(); ++curValue) {\n"
|
||||
" a = bar(*curValue);\n"
|
||||
" prevValue = curValue;\n"
|
||||
" }\n"
|
||||
" if (endValue == mValues.end()) {}\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #10642
|
||||
check("int f(std::vector<int> v) {\n"
|
||||
" return *(v.begin() + v.size() - 1);\n"
|
||||
|
|
Loading…
Reference in New Issue