From 8ef4da475a781b43eeeb936c5f47206a12aa7101 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 12 Oct 2023 16:27:10 +0200 Subject: [PATCH] Add test for #2456, #12011 (#5544) --- test/testother.cpp | 10 ++++++++++ test/testuninitvar.cpp | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index 60ab9c480..eede3d694 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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" diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 960d2a6b7..6e4abe8d8 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -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()); }