From 75153055816cd233ffbde60845df928e3102bed2 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 18 Jan 2023 17:30:22 +0100 Subject: [PATCH] Add test for #10413 (#4687) --- test/testbufferoverrun.cpp | 18 +++++++++++++++++- test/testnullpointer.cpp | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index c08f6d139..074182749 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -1724,7 +1724,7 @@ private: errout.str()); } - void array_index_59() + void array_index_59() // #10413 { check("long f(long b) {\n" " const long a[] = { 0, 1, };\n" @@ -1734,6 +1734,22 @@ private: " return a[b];\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("void f(int a, int b) {\n" + " const int S[2] = {};\n" + " if (a < 0) {}\n" + " else {\n" + " if (b < 0) {}\n" + " else if (S[b] > S[a]) {}\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + + check("int a[2] = {};\n" + "void f(int i) {\n" + " g(i < 0 ? 0 : a[i]);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void array_index_60() diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index e72194af0..e9d25759d 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -2790,7 +2790,7 @@ private: "struct D : public B { int f() override; };\n" "int g(B* p) {\n" " if (p) {\n" - " auto d = dynamic_cast(p);\n" + " auto d = dynamic_cast(p);\n" " return d ? d->f() : 0;\n" " }\n" " return 0;\n"