From 4b4325bdaf80e8fd53d9cf1c3147b39de43f138a Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 7 Jan 2025 19:32:53 +0100 Subject: [PATCH 1/2] Update vf_settokenvalue.cpp --- lib/vf_settokenvalue.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vf_settokenvalue.cpp b/lib/vf_settokenvalue.cpp index 5e640e67dfe..f2b92a86f13 100644 --- a/lib/vf_settokenvalue.cpp +++ b/lib/vf_settokenvalue.cpp @@ -479,7 +479,7 @@ namespace ValueFlow if (!isComputableValue(parent, value1)) continue; for (const Value &value2 : parent->astOperand2()->values()) { - if (value1.path != value2.path) + if (value1.path != value2.path && value1.path != 0 && value2.path != 0) continue; if (!isComputableValue(parent, value2)) continue; From 0cd4eeb3cc67a2e247195c22a4dd9fa8684f9d92 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 7 Jan 2025 19:34:09 +0100 Subject: [PATCH 2/2] Update testother.cpp --- test/testother.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index 74801ec4559..b0a76891dd1 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -59,6 +59,7 @@ class TestOther : public TestFixture { TEST_CASE(zeroDiv18); TEST_CASE(zeroDiv19); TEST_CASE(zeroDiv20); // #11175 + TEST_CASE(zeroDiv21); TEST_CASE(zeroDivCond); // division by zero / useless condition @@ -679,6 +680,17 @@ class TestOther : public TestFixture { ASSERT_EQUALS("[test.cpp:4]: (error) Division by zero.\n", errout_str()); } + void zeroDiv21() + { + check("int f(int n) {\n" + " return 1 / ((1 / n) - 1);\n" + "}\n" + "int g() {\n" + " return f(1);\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:2]: (error) Division by zero.\n", errout_str()); + } + void zeroDivCond() { check("void f(unsigned int x) {\n" " int y = 17 / x;\n"