From 212e735b62a1459efbaa8c68f864f07a7eb73812 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 23 Sep 2026 09:44:16 +0200 Subject: [PATCH 1/3] Update checkstl.cpp --- lib/checkstl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 637f5e1e8b8..d99716d433a 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -3338,8 +3338,8 @@ void CheckStlImpl::eraseIteratorOutOfBoundsError(const Token *ftok, const Token* } const Severity severity = isConditional ? Severity::warning : Severity::error; - const std::string id = isConditional ? "eraseIteratorOutOfBoundsCond" : "eraseIteratorOutOfBounds"; - reportError(ftok, severity, + const char* id = isConditional ? "eraseIteratorOutOfBoundsCond" : "eraseIteratorOutOfBounds"; + reportError(getErrorPath(ftok, val, msg), severity, id, msg, CWE628, Certainty::normal); } From 662c6ce258b281e2ed396ae84f5ecac8573a81b0 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 23 Sep 2026 09:45:13 +0200 Subject: [PATCH 2/3] Update teststl.cpp --- test/teststl.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/teststl.cpp b/test/teststl.cpp index 197cc3fafa7..f56b9186a03 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -1140,6 +1140,20 @@ class TestStl : public TestFixture { "[test.cpp:3:11]: note: Assuming that condition 'i>5' is not redundant\n" "[test.cpp:5:13]: note: Access out of bounds\n", errout_str()); + + check("void f(std::vector& v) {\n" + " std::vector::iterator it;\n" + " for (it = v.begin(); it != v.end(); ++it) {\n" + " if (*it == 0)\n" + " break;\n" + " }\n" + " v.erase(it);\n" + "}\n", s); + ASSERT_EQUALS("[test.cpp:4:13]: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]\n" + "[test.cpp:7:7]: warning: Either the condition is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBoundsCond]\n" + "[test.cpp:3:29]: note: Assuming that condition 'it!=v.end()' is not redundant\n" + "[test.cpp:7:7]: note: Either the condition is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds.\n", + errout_str()); } void iterator1() { From 3fc280cfed4169a141cb32908bcb12f4efcc714f Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 23 Sep 2026 09:45:41 +0200 Subject: [PATCH 3/3] Update teststl.cpp --- test/teststl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/teststl.cpp b/test/teststl.cpp index f56b9186a03..e7b77119321 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -2455,7 +2455,7 @@ class TestStl : public TestFixture { " if (it == v.end()) {}\n" " v.erase(it);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:3:7]: (warning) Either the condition 'it==v.end()' is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBoundsCond]\n", + ASSERT_EQUALS("[test.cpp:2:12] -> [test.cpp:3:7]: (warning) Either the condition 'it==v.end()' is redundant or function 'erase()' is called on the iterator 'it' which is out of bounds. [eraseIteratorOutOfBoundsCond]\n", errout_str()); check("void f() {\n"