From 72ac4fc1eb5b0cb588c216d95edda9711278d26f Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 18 Mar 2026 16:13:49 +0100 Subject: [PATCH 1/4] Update valueflow.cpp --- lib/valueflow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index f7e057da58f..f83d288672f 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -903,10 +903,10 @@ static void valueFlowSameExpressions(TokenList& tokenlist, const Settings& setti long long val; - if (Token::Match(tok, "==|>=|<=|/")) { + if (Token::Match(tok, "==|>=|<=|/|/=")) { val = 1; } - else if (Token::Match(tok, "!=|>|<|%|-")) { + else if (Token::Match(tok, "!=|>|<|%|%=|-|-=|^|^=")) { val = 0; } else From c59f47c1dc4386800a51addbdc47a081f05a9add Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 18 Mar 2026 16:14:30 +0100 Subject: [PATCH 2/4] Update token.cpp --- lib/token.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/token.cpp b/lib/token.cpp index 5424ac3396e..4d1d2f5890f 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -554,7 +554,7 @@ int multiCompareImpl(const Token *tok, const char *haystack, nonneg int varid) const char *needle = tok->str().c_str(); const char *needlePointer = needle; for (;;) { - if (needlePointer == needle && haystack[0] == '%' && haystack[1] != '|' && haystack[1] != '\0' && haystack[1] != ' ') { + if (needlePointer == needle && haystack[0] == '%' && haystack[1] != '|' && haystack[1] != '\0' && haystack[1] != ' ' && haystack[1] != '=') { const int ret = multiComparePercent(tok, haystack, varid); if (ret < 2) return ret; From 11a7c8e167e9f9bcb161318ac8eee822e51a18a7 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 18 Mar 2026 16:16:09 +0100 Subject: [PATCH 3/4] Update testvalueflow.cpp --- test/testvalueflow.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 709be2a204f..eec0645383b 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -5805,6 +5805,30 @@ class TestValueFlow : public TestFixture { " bool b = x;\n" "}\n"; ASSERT_EQUALS(false, testValueOfX(code, 3U, 1)); + + code = "int f(int a) {\n" + " int x = a ^ a;\n" + " return x;\n" + "}\n"; + ASSERT_EQUALS(true, testValueOfX(code, 3U, 0)); + + code = "int f(int a) {\n" + " int x = a /= a;\n" + " return x;\n" + "}\n"; + ASSERT_EQUALS(true, testValueOfX(code, 3U, 1)); + + code = "int f(int a) {\n" + " int x = a -= a;\n" + " return x;\n" + "}\n"; + ASSERT_EQUALS(true, testValueOfX(code, 3U, 0)); + + code = "int f(int a) {\n" + " int x = a %= a;\n" + " return x;\n" + "}\n"; + ASSERT_EQUALS(true, testValueOfX(code, 3U, 0)); } void valueFlowUninit() { From 109ea08223645549d484d17b0af8b9436434d3bf Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Wed, 18 Mar 2026 19:12:21 +0100 Subject: [PATCH 4/4] Format, add tests --- test/testtoken.cpp | 12 ++++++++++++ test/testvalueflow.cpp | 30 ++++++++++++++++++------------ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/test/testtoken.cpp b/test/testtoken.cpp index 2b411324dc7..83a514eb963 100644 --- a/test/testtoken.cpp +++ b/test/testtoken.cpp @@ -64,6 +64,7 @@ class TestToken : public TestFixture { TEST_CASE(multiCompare3); // false positive for %or% on code using "|=" TEST_CASE(multiCompare4); TEST_CASE(multiCompare5); + TEST_CASE(multiCompare6); TEST_CASE(charTypes); TEST_CASE(stringTypes); TEST_CASE(getStrLength); @@ -322,6 +323,17 @@ class TestToken : public TestFixture { ASSERT_EQUALS(true, TokenTest::multiCompare(&tok, "+|%or%|%oror%", 0) >= 0); } + void multiCompare6() const { + { + const SimpleTokenList stl("x %= y;"); + ASSERT_EQUALS(true, Token::Match(stl.front(), "%name% %= %name%")); + } + { + const SimpleTokenList stl("x += y;"); + ASSERT_EQUALS(false, Token::Match(stl.front(), "%name% %= %name%")); + } + } + void charTypes() const { auto tokensFrontBack = std::make_shared(); Token tok(list, std::move(tokensFrontBack)); diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index eec0645383b..2d003e41a09 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -5807,27 +5807,33 @@ class TestValueFlow : public TestFixture { ASSERT_EQUALS(false, testValueOfX(code, 3U, 1)); code = "int f(int a) {\n" - " int x = a ^ a;\n" - " return x;\n" - "}\n"; + " int x = a ^ a;\n" + " return x;\n" + "}\n"; ASSERT_EQUALS(true, testValueOfX(code, 3U, 0)); code = "int f(int a) {\n" - " int x = a /= a;\n" - " return x;\n" - "}\n"; + " int x = a /= a;\n" + " return x;\n" + "}\n"; ASSERT_EQUALS(true, testValueOfX(code, 3U, 1)); code = "int f(int a) {\n" - " int x = a -= a;\n" - " return x;\n" - "}\n"; + " int x = a -= a;\n" + " return x;\n" + "}\n"; ASSERT_EQUALS(true, testValueOfX(code, 3U, 0)); code = "int f(int a) {\n" - " int x = a %= a;\n" - " return x;\n" - "}\n"; + " int x = a %= a;\n" + " return x;\n" + "}\n"; + ASSERT_EQUALS(true, testValueOfX(code, 3U, 0)); + + code = "int f(int a) {\n" + " int x = a ^= a;\n" + " return x;\n" + "}\n"; ASSERT_EQUALS(true, testValueOfX(code, 3U, 0)); }