From fb177b148b466a37e186d34bd448fb096cb434c6 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 17 Nov 2026 15:47:31 +0100 Subject: [PATCH 1/5] Update valueflow.cpp --- lib/valueflow.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 7f4cd5584e8..e26bcb0c439 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -7612,8 +7612,6 @@ const ValueFlow::Value* ValueFlow::findValue(const std::list& if (ret) { if (ret->isInconclusive() && !settings.certainty.isEnabled(Certainty::inconclusive)) return nullptr; - if (ret->condition && !settings.severity.isEnabled(Severity::warning)) - return nullptr; } return ret; } From c510f586ac8a7d52442dd4ef0600f6274bb9e1de Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 17 Nov 2026 15:49:49 +0100 Subject: [PATCH 2/5] Update testother.cpp --- test/testother.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index d6025e9a640..cbeca3ed72b 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -10603,6 +10603,13 @@ class TestOther : public TestFixture { " return f<-1>(2)\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + Settings settings = settingsBuilder(settings0).severity(Severity::portability).build(); + check("int f(int k, int& s) {\n" // #7215 + " if (k >= -128 && k <= 127)\n" + " s = (k << 8);\n" + "}\n", dinit(CheckOptions, $.settings = &settings)); + ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:3:16]: (portability) Shifting a negative value is technically undefined behaviour [shiftNegativeLHS]\n", errout_str()); } void checkNegativeShiftErrorPath() { From a8fa0274894950cd0195912010d1d0d5b8fc197e Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 18 Nov 2026 09:13:58 +0100 Subject: [PATCH 3/5] Update checkstl.cpp [skip ci] --- lib/checkstl.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 0b3bd405c3d..ed02705b528 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -1409,6 +1409,8 @@ void CheckStlImpl::negativeIndexError(const Token *tok, const ValueFlow::Value & else errmsg << "Array index " << index.intvalue << " is out of bounds."; const auto severity = index.errorSeverity() && index.isKnown() ? Severity::error : Severity::warning; + if (!mSettings.severity.isEnabled(severity)) + return; const auto certainty = index.isInconclusive() ? Certainty::inconclusive : Certainty::normal; reportError(std::move(errorPath), severity, "negativeContainerIndex", errmsg.str(), CWE786, certainty); } From 308b50ec158e1ce0d93e728110f7fb1b3c848587 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 18 Nov 2026 09:14:23 +0100 Subject: [PATCH 4/5] Update teststl.cpp --- test/teststl.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/test/teststl.cpp b/test/teststl.cpp index 7dbdf7793f0..242f102a222 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -3176,13 +3176,31 @@ class TestStl : public TestFixture { "}\n"); ASSERT_EQUALS("", errout_str()); - Settings s = settings; - s.daca = true; + { + Settings s = settings; + s.daca = true; - check("void f() {\n" - " const char a[][5] = { \"1\", \"true\", \"on\", \"yes\" };\n" - "}\n", s); - ASSERT_EQUALS("", errout_str()); + check("void f() {\n" + " const char a[][5] = { \"1\", \"true\", \"on\", \"yes\" };\n" + "}\n", s); + ASSERT_EQUALS("", errout_str()); + } + + { + Settings s = settings; + const char code[] = "char f(const std::string& s, bool b) {\n" + " int i = -1;\n" + " if (b)\n" + " i = 0;\n" + " return s[i];\n" + "}\n"; + check(code, s); + ASSERT_EQUALS("[test.cpp:5:12]: (warning) Array index -1 is out of bounds. [negativeContainerIndex]\n", errout_str()); + + s.severity.disable(Severity::warning); + check(code, s); + ASSERT_EQUALS("", errout_str()); + } } void negativeIndexMultiline() { From 928aaa90d5be94f984f28b715570123e4464fa2e Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 18 Nov 2026 09:42:07 +0100 Subject: [PATCH 5/5] Update teststl.cpp --- test/teststl.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/teststl.cpp b/test/teststl.cpp index 242f102a222..837741dd7f4 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -3181,13 +3181,13 @@ class TestStl : public TestFixture { s.daca = true; check("void f() {\n" - " const char a[][5] = { \"1\", \"true\", \"on\", \"yes\" };\n" - "}\n", s); + " const char a[][5] = { \"1\", \"true\", \"on\", \"yes\" };\n" + "}\n", s); ASSERT_EQUALS("", errout_str()); } { - Settings s = settings; + Settings s = settings; const char code[] = "char f(const std::string& s, bool b) {\n" " int i = -1;\n" " if (b)\n"