Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/vf_settokenvalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down
Loading