diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 264ecab0d..b5bc660da 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -2329,7 +2329,7 @@ void CheckStl::checkDereferenceInvalidIterator2() inconclusive = true; } if (cValue) { - const ValueFlow::Value& lValue = getLifetimeObjValue(tok, true); + const ValueFlow::Value& lValue = getLifetimeIteratorValue(tok); if (emptyAdvance) outOfBoundsError(emptyAdvance, lValue.tokvalue->expressionString(), diff --git a/test/teststl.cpp b/test/teststl.cpp index 0d27837cd..4357c5049 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -4243,6 +4243,20 @@ private: " return *(v.begin() + v.size() - 1);\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // #10716 + check("struct a;\n" + "class b {\n" + " void c(std::map &);\n" + " std::string d;\n" + " std::map> e;\n" + "};\n" + "void b::c(std::map &) {\n" + " e.clear();\n" + " auto f = *e[d].begin();\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:9]: (error) Out of bounds access in expression 'e[d].begin()' because 'e[d]' is empty.\n", + errout.str()); } void dereferenceInvalidIterator2() {