This commit is contained in:
chrchr-github 2023-10-12 16:27:10 +02:00 committed by GitHub
parent 9d4e3829c2
commit 8ef4da475a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View File

@ -61,6 +61,7 @@ private:
TEST_CASE(zeroDiv16); // #11158
TEST_CASE(zeroDiv17); // #9931
TEST_CASE(zeroDiv18);
TEST_CASE(zeroDiv19);
TEST_CASE(zeroDivCond); // division by zero / useless condition
@ -655,6 +656,15 @@ private:
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"

View File

@ -1251,6 +1251,23 @@ private:
" 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());
}