From 55c71f401586999719792b7ce75767e1132c0672 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 3 May 2024 11:01:32 +0200 Subject: [PATCH] Fix #12680 Assert failure in checkDereferenceInvalidIterator2() (#6366) --- lib/checkstl.cpp | 1 - test/teststl.cpp | 12 ++++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 32554ce0c7e..54da256288c 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -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) diff --git a/test/teststl.cpp b/test/teststl.cpp index 75b8b659786..f32d4b40713 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -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 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() {