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; 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"