Skip to content

Commit

Permalink
Fix #12680 Assert failure in checkDereferenceInvalidIterator2() (danm…
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed May 3, 2024
1 parent 50dc589 commit 55c71f4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/checkstl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2492,7 +2492,6 @@ void CheckStl::checkDereferenceInvalidIterator2()
}
if (cValue) {
const ValueFlow::Value& lValue = getLifetimeIteratorValue(tok, cValue->path);
assert(cValue->isInconclusive() || value.isInconclusive() || lValue.isLifetimeValue());
if (!lValue.isLifetimeValue())
continue;
if (emptyAdvance)
Expand Down
12 changes: 12 additions & 0 deletions test/teststl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5070,6 +5070,18 @@ class TestStl : public TestFixture {
"}\n");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (warning) Either the condition 'i+1!=s.end()' is redundant or there is possible dereference of an invalid iterator: i+1.\n",
errout_str());

check("void f(bool b, std::vector<std::string> v) {\n" // #12680
" if (!v.empty()) {\n"
" auto it = v.begin();\n"
" if (b) {\n"
" v.clear();\n"
" it = v.begin();\n"
" }\n"
" for (++it; it != v.end(); ++it) {}\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout_str()); // don't crash
}

void dereferenceInvalidIterator2() {
Expand Down

0 comments on commit 55c71f4

Please sign in to comment.