Skip to content

Commit 6f3e98e

Browse files
Partial fix for #13529 FN: zerodiv (#7191)
1 parent 0fdc470 commit 6f3e98e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/vf_settokenvalue.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ namespace ValueFlow
479479
if (!isComputableValue(parent, value1))
480480
continue;
481481
for (const Value &value2 : parent->astOperand2()->values()) {
482-
if (value1.path != value2.path)
482+
if (value1.path != value2.path && value1.path != 0 && value2.path != 0)
483483
continue;
484484
if (!isComputableValue(parent, value2))
485485
continue;

test/testother.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class TestOther : public TestFixture {
5959
TEST_CASE(zeroDiv18);
6060
TEST_CASE(zeroDiv19);
6161
TEST_CASE(zeroDiv20); // #11175
62+
TEST_CASE(zeroDiv21);
6263

6364
TEST_CASE(zeroDivCond); // division by zero / useless condition
6465

@@ -679,6 +680,17 @@ class TestOther : public TestFixture {
679680
ASSERT_EQUALS("[test.cpp:4]: (error) Division by zero.\n", errout_str());
680681
}
681682

683+
void zeroDiv21()
684+
{
685+
check("int f(int n) {\n"
686+
" return 1 / ((1 / n) - 1);\n"
687+
"}\n"
688+
"int g() {\n"
689+
" return f(1);\n"
690+
"}\n");
691+
ASSERT_EQUALS("[test.cpp:2]: (error) Division by zero.\n", errout_str());
692+
}
693+
682694
void zeroDivCond() {
683695
check("void f(unsigned int x) {\n"
684696
" int y = 17 / x;\n"

0 commit comments

Comments
 (0)