This commit is contained in:
chrchr-github 2023-05-04 20:35:56 +02:00 committed by GitHub
parent a77ab9759c
commit a31c996a70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 0 deletions

View File

@ -141,6 +141,7 @@ private:
TEST_CASE(nullpointer98); // #11458 TEST_CASE(nullpointer98); // #11458
TEST_CASE(nullpointer99); // #10602 TEST_CASE(nullpointer99); // #10602
TEST_CASE(nullpointer100); // #11636 TEST_CASE(nullpointer100); // #11636
TEST_CASE(nullpointer101); // #11382
TEST_CASE(nullpointer_addressOf); // address of TEST_CASE(nullpointer_addressOf); // address of
TEST_CASE(nullpointerSwitch); // #2626 TEST_CASE(nullpointerSwitch); // #2626
TEST_CASE(nullpointer_cast); // #4692 TEST_CASE(nullpointer_cast); // #4692
@ -2839,6 +2840,18 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void nullpointer101() // #11382
{
check("struct Base { virtual ~Base(); };\n"
"struct Derived : Base {};\n"
"bool is_valid(const Derived&);\n"
"void f(const Base* base) {\n"
" const Derived* derived = dynamic_cast<const Derived*>(base);\n"
" if (derived && !is_valid(*derived) || base == nullptr) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void nullpointer_addressOf() { // address of void nullpointer_addressOf() { // address of
check("void f() {\n" check("void f() {\n"
" struct X *x = 0;\n" " struct X *x = 0;\n"

View File

@ -6026,6 +6026,33 @@ private:
" g(p);\n" " g(p);\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
valueFlowUninit("struct T {};\n" // #11075
"struct S {\n"
" int n;\n"
" struct T t[10];\n"
"};\n"
"void f(struct S* s, char** tokens) {\n"
" struct T t[10];\n"
" int n = 0;\n"
" for (int i = 0; i < s->n; i++)\n"
" if (tokens[i])\n"
" t[n++] = s->t[i];\n"
" for (int i = 0; i < n; i++)\n"
" t[i];\n"
"}\n", "test.c");
ASSERT_EQUALS("", errout.str());
valueFlowUninit("bool g();\n"
"void f() {\n"
" int a[10];\n"
" int idx = 0;\n"
" if (g())\n"
" a[idx++] = 1;\n"
" for (int i = 0; i < idx; i++)\n"
" (void)a[i];\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value