Skip to content

Commit 55c71f4

Browse files
Fix #12680 Assert failure in checkDereferenceInvalidIterator2() (#6366)
1 parent 50dc589 commit 55c71f4

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

lib/checkstl.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2492,7 +2492,6 @@ void CheckStl::checkDereferenceInvalidIterator2()
24922492
}
24932493
if (cValue) {
24942494
const ValueFlow::Value& lValue = getLifetimeIteratorValue(tok, cValue->path);
2495-
assert(cValue->isInconclusive() || value.isInconclusive() || lValue.isLifetimeValue());
24962495
if (!lValue.isLifetimeValue())
24972496
continue;
24982497
if (emptyAdvance)

test/teststl.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5070,6 +5070,18 @@ class TestStl : public TestFixture {
50705070
"}\n");
50715071
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",
50725072
errout_str());
5073+
5074+
check("void f(bool b, std::vector<std::string> v) {\n" // #12680
5075+
" if (!v.empty()) {\n"
5076+
" auto it = v.begin();\n"
5077+
" if (b) {\n"
5078+
" v.clear();\n"
5079+
" it = v.begin();\n"
5080+
" }\n"
5081+
" for (++it; it != v.end(); ++it) {}\n"
5082+
" }\n"
5083+
"}\n");
5084+
ASSERT_EQUALS("", errout_str()); // don't crash
50735085
}
50745086

50755087
void dereferenceInvalidIterator2() {

0 commit comments

Comments
 (0)