Add tests for # 6561, #6619, #7475 (#4988)

* Add tests for #6925, #11042, #11494

* Format

* Add tests for # 6561, #6619, #7475,
This commit is contained in:
chrchr-github 2023-04-20 12:58:50 +02:00 committed by GitHub
parent bf3be95046
commit 67a8ff0b27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View File

@ -5968,6 +5968,27 @@ private:
" if (a[0]) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// #6619
valueFlowUninit("void f() {\n"
" int nok, i;\n"
" for (i = 1; i < 5; i++) {\n"
" if (i == 8)\n"
" nok = 8;\n"
" }\n"
" printf(\"nok = %d\\n\", nok);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:7]: (warning) Uninitialized variable: nok\n", errout.str());
// #7475
valueFlowUninit("struct S {\n"
" int a, b, c;\n"
"} typedef s_t;\n"
"void f() {\n"
" s_t s;\n"
" printf(\"%d\", s.a);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: s.a\n", errout.str());
}
void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value

View File

@ -1640,6 +1640,14 @@ private:
"\n"
"input.skip(sizeof(struct Header));");
ASSERT_EQUALS("", errout.str());
checkStructMemberUsage("struct S { int a, b, c; };\n" // #6561
"int f(FILE * fp) {\n"
" S s;\n"
" ::fread(&s, sizeof(S), 1, fp);\n"
" return s.b;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void structmember16() {