Skip to content

Added regression test for ticket #13474 #7536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 2 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
22 changes: 22 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class TestOther : public TestFixture {
TEST_CASE(zeroDiv19);
TEST_CASE(zeroDiv20); // #11175
TEST_CASE(zeroDiv21);
TEST_CASE(zeroDivInLoop);

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

Expand Down Expand Up @@ -700,6 +701,27 @@ class TestOther : public TestFixture {
ASSERT_EQUALS("[test.cpp:2:14]: (error) Division by zero. [zerodiv]\n", errout_str());
}

void zeroDivInLoop()
{
// single for loop
check("void f(void) {\n"
" for (int j = 1; j >= 0; --j) {\n"
" int result = 42 / j;\n" // << Division by zero when j is 0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is same as zeroDiv19

" }\n"
"}");
ASSERT_EQUALS("[test.cpp:3:24]: (error) Division by zero. [zerodiv]\n", errout_str());

// nested for loop
check("void f(void) {\n"
" for (int i = 2; i >= 0; --i) {\n"
" for (int j = 1; j >= 0; --j) {\n"
" int result = 42 / (i * j);\n" // << Division by zero when i or j is 0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still dislike this test as it won't detect if there is a regression.

" }\n"
" }\n"
"}");
ASSERT_EQUALS("[test.cpp:4:29]: (error) Division by zero. [zerodiv]\n", errout_str());
}

void zeroDivCond() {
check("void f(unsigned int x) {\n"
" int y = 17 / x;\n"
Expand Down
Loading