From 2fee7a6e3fe04c4ebbd00f0e8eb3de5f9fe6b336 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 18 Aug 2022 23:37:41 +0200 Subject: [PATCH] Add test for #9744, #11140 (#4375) * Add test for #10603 * Add test for #10559 * Add test for #10212 * Format * Add test for #9744 * Format * Add test for #11140 --- test/testbufferoverrun.cpp | 13 +++++++++++++ test/testother.cpp | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 65dba6d49..b47f8c251 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -3585,6 +3585,19 @@ private: " f(\"bbb\", 3);\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("void f(int i, const char* a) {\n" // #11140 + " (void)a[i];\n" + "}\n" + "void g() {\n" + " for (int i = 0; \"01234\"[i]; ++i)\n" + " f(i, \"56789\");\n" + "}\n" + "void h() {\n" + " for (int i = 0; \"012\"[i]; ++i)\n" + " f(i, \"345\");\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } diff --git a/test/testother.cpp b/test/testother.cpp index 32c86d81b..3739a8ea6 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -5964,6 +5964,15 @@ private: " }\n" "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:5]: (style) The comparison 'Diag == 0' is always true.\n", errout.str()); + + // #9744 + check("void f(const std::vector& ints) {\n" + " int i = 0;\n" + " for (int p = 0; i < ints.size(); ++i) {\n" + " if (p == 0) {}\n" + " }\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) The comparison 'p == 0' is always true.\n", errout.str()); } void duplicateExpression8() {