Skip to content

Commit

Permalink
Add test for danmar#2456, #12011 (danmar#5544)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Oct 12, 2023
1 parent 9d4e382 commit 8ef4da4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class TestOther : public TestFixture {
TEST_CASE(zeroDiv16); // #11158
TEST_CASE(zeroDiv17); // #9931
TEST_CASE(zeroDiv18);
TEST_CASE(zeroDiv19);

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

Expand Down Expand Up @@ -655,6 +656,15 @@ class TestOther : public TestFixture {
errout.str());
}

void zeroDiv19()
{
check("void f() {\n" // #2456
" for (int i = 0;;)\n"
" int j = 10 / i;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero.\n", errout.str());
}

void zeroDivCond() {
check("void f(unsigned int x) {\n"
" int y = 17 / x;\n"
Expand Down
17 changes: 17 additions & 0 deletions test/testuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,23 @@ class TestUninitVar : public TestFixture {
" if (!flag || x == 0) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());

checkUninitVar("void f(int n, int a) {\n" // #12011
" double x[10];\n"
" if (n == 1) {\n"
" if (a)\n"
" x[0] = 4;\n"
" }\n"
" else\n"
" for (int i = 0; i < n; i++) {\n"
" if (a)\n"
" x[i] = 8;\n"
" }\n"
" if (n == 1)\n"
" if (a)\n"
" (void)x[0];\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}


Expand Down

0 comments on commit 8ef4da4

Please sign in to comment.