Dont diagnose impossible values for iterators (#2755)

This commit is contained in:
Paul Fultz II 2020-08-25 23:58:53 -05:00 committed by GitHub
parent 31d7acb99a
commit 46bf2d7d52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -2025,6 +2025,8 @@ void CheckStl::checkDereferenceInvalidIterator2()
// Can iterator point to END or before START?
for (const ValueFlow::Value& value:tok->values()) {
if (value.isImpossible())
continue;
if (!printInconclusive && value.isInconclusive())
continue;
if (!value.isIteratorValue())

View File

@ -3571,6 +3571,12 @@ private:
" *(i-1)=0;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (warning) Possible dereference of an invalid iterator: i-1\n", errout.str());
check("int f(std::vector<int> v, int pos) {\n"
" if (pos >= 0)\n"
" return *(v.begin() + pos);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void dereferenceInvalidIterator2() {