From 16d3369304f4f6097f7ac2561336e563b39bad0c Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 7 Aug 2026 14:39:36 +0200 Subject: [PATCH 1/5] Update checkstl.cpp --- lib/checkstl.cpp | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index de1d82792ac..a5f1f582c4d 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -259,20 +259,11 @@ void CheckStlImpl::outOfBoundsError(const Token *tok, const std::string &contain return; } - ErrorPath errorPath; - if (!indexValue) - errorPath = getErrorPath(tok, containerSize, "Access out of bounds"); - else { - ErrorPath errorPath1 = getErrorPath(tok, containerSize, "Access out of bounds"); - ErrorPath errorPath2 = getErrorPath(tok, indexValue, "Access out of bounds"); - if (errorPath1.size() <= 1) - errorPath = std::move(errorPath2); - else if (errorPath2.size() <= 1) - errorPath = std::move(errorPath1); - else { - errorPath = std::move(errorPath1); - errorPath.splice(errorPath.end(), errorPath2); - } + ErrorPath errorPath = getErrorPath(tok, containerSize, "Access out of bounds"); + if (indexValue) { + ErrorPath errorPathIdx = getErrorPath(tok, indexValue, "Access out of bounds"); + if (errorPathIdx.size() >= errorPath.size()) + errorPath = std::move(errorPathIdx); } reportError(std::move(errorPath), From 8683bd324c38b16fee3888735e2e26b90c3a3595 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 7 Aug 2026 14:40:49 +0200 Subject: [PATCH 2/5] Update teststl.cpp --- test/teststl.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/teststl.cpp b/test/teststl.cpp index 2570059c19e..6f5b1106ee8 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -42,6 +42,7 @@ class TestStl : public TestFixture { TEST_CASE(outOfBoundsSymbolic); TEST_CASE(outOfBoundsIndexExpression); TEST_CASE(outOfBoundsIterator); + TEST_CASE(outOfBoundsErrorPath; TEST_CASE(iterator1); TEST_CASE(iterator2); @@ -1124,6 +1125,21 @@ class TestStl : public TestFixture { errout_str()); } + void outOfBoundsErrorPath() { + Settings s = settings; + s.templateLocation = "{file}:{line}:note:{info}"; + check("int f(int i) {\n" + " std::string s = \"abc\";\n" + " if (i > 5)\n" + " return 0;\n" + " return s[i];\n" + "}\n", s); + ASSERT_EQUALS("[test.cpp:5:13]: warning: Either the condition 'i>5' is redundant or 'i' can have the value 5. Expression 's[i]' causes access out of bounds. [containerOutOfBounds]\n" + "[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()); + } + void iterator1() { check("void f()\n" "{\n" From 799d23961fb34f5254532b8bc50dd3677af031c1 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 7 Aug 2026 14:45:14 +0200 Subject: [PATCH 3/5] 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 6f5b1106ee8..85cd29acb8e 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -42,7 +42,7 @@ class TestStl : public TestFixture { TEST_CASE(outOfBoundsSymbolic); TEST_CASE(outOfBoundsIndexExpression); TEST_CASE(outOfBoundsIterator); - TEST_CASE(outOfBoundsErrorPath; + TEST_CASE(outOfBoundsErrorPath); TEST_CASE(iterator1); TEST_CASE(iterator2); From 6590a1168ce96a4e89d69d03005c0dda2f36f64d Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 7 Aug 2026 14:50:27 +0200 Subject: [PATCH 4/5] Update teststl.cpp --- test/teststl.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/teststl.cpp b/test/teststl.cpp index 85cd29acb8e..95e94876a8d 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -1126,8 +1126,10 @@ class TestStl : public TestFixture { } void outOfBoundsErrorPath() { + setMultiline(); Settings s = settings; s.templateLocation = "{file}:{line}:note:{info}"; + check("int f(int i) {\n" " std::string s = \"abc\";\n" " if (i > 5)\n" From 01e6d9c95019eeb78a0607b48c935cfef962e8d6 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 7 Aug 2026 16:36:03 +0200 Subject: [PATCH 5/5] Format --- test/teststl.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/teststl.cpp b/test/teststl.cpp index 95e94876a8d..677147bf0ce 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -1131,11 +1131,11 @@ class TestStl : public TestFixture { s.templateLocation = "{file}:{line}:note:{info}"; check("int f(int i) {\n" - " std::string s = \"abc\";\n" - " if (i > 5)\n" - " return 0;\n" - " return s[i];\n" - "}\n", s); + " std::string s = \"abc\";\n" + " if (i > 5)\n" + " return 0;\n" + " return s[i];\n" + "}\n", s); ASSERT_EQUALS("[test.cpp:5:13]: warning: Either the condition 'i>5' is redundant or 'i' can have the value 5. Expression 's[i]' causes access out of bounds. [containerOutOfBounds]\n" "[test.cpp:3:11]: note: Assuming that condition 'i>5' is not redundant\n" "[test.cpp:5:13]: note: Access out of bounds\n",