From 66e25b7063dbd3c7f9e6597e05c2c2555940010a Mon Sep 17 00:00:00 2001 From: chrchr Date: Thu, 12 Oct 2023 13:48:41 +0200 Subject: [PATCH 1/2] Add test for #2456 --- test/testother.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index 60ab9c4801c..eede3d6949b 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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 @@ -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" From bc376af59a7756f3991d3982efac699be3996492 Mon Sep 17 00:00:00 2001 From: chrchr Date: Thu, 12 Oct 2023 14:24:14 +0200 Subject: [PATCH 2/2] Add test for #12011 --- test/testuninitvar.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 960d2a6b7d7..6e4abe8d876 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -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()); }