From 970af2fa80581193c91b95c54b1d477394f7d4c9 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 30 Apr 2024 12:41:45 +0200 Subject: [PATCH 1/3] Update checkstl.cpp --- lib/checkstl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 32554ce0c7e..12f2ec920d4 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -2492,9 +2492,9 @@ void CheckStl::checkDereferenceInvalidIterator2() } if (cValue) { const ValueFlow::Value& lValue = getLifetimeIteratorValue(tok, cValue->path); - assert(cValue->isInconclusive() || value.isInconclusive() || lValue.isLifetimeValue()); if (!lValue.isLifetimeValue()) continue; + assert(cValue->isInconclusive() || value.isInconclusive()); if (emptyAdvance) outOfBoundsError(emptyAdvance, lValue.tokvalue->expressionString(), From a72ebdae6375b4766d24faa6545091380e1cf267 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 30 Apr 2024 12:50:12 +0200 Subject: [PATCH 2/3] Update teststl.cpp --- test/teststl.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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() { From f9e64361f2d22bb9730ccbaf0ab9df24098dae5f Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 30 Apr 2024 13:13:02 +0200 Subject: [PATCH 3/3] Update checkstl.cpp --- lib/checkstl.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 12f2ec920d4..54da256288c 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -2494,7 +2494,6 @@ void CheckStl::checkDereferenceInvalidIterator2() const ValueFlow::Value& lValue = getLifetimeIteratorValue(tok, cValue->path); if (!lValue.isLifetimeValue()) continue; - assert(cValue->isInconclusive() || value.isInconclusive()); if (emptyAdvance) outOfBoundsError(emptyAdvance, lValue.tokvalue->expressionString(),