Skip to content

Commit 67a8ff0

Browse files
Add tests for # 6561, #6619, #7475 (#4988)
* Add tests for #6925, #11042, #11494 * Format * Add tests for # 6561, #6619, #7475,
1 parent bf3be95 commit 67a8ff0

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

test/testuninitvar.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5968,6 +5968,27 @@ class TestUninitVar : public TestFixture {
59685968
" if (a[0]) {}\n"
59695969
"}\n");
59705970
ASSERT_EQUALS("", errout.str());
5971+
5972+
// #6619
5973+
valueFlowUninit("void f() {\n"
5974+
" int nok, i;\n"
5975+
" for (i = 1; i < 5; i++) {\n"
5976+
" if (i == 8)\n"
5977+
" nok = 8;\n"
5978+
" }\n"
5979+
" printf(\"nok = %d\\n\", nok);\n"
5980+
"}\n");
5981+
ASSERT_EQUALS("[test.cpp:7]: (warning) Uninitialized variable: nok\n", errout.str());
5982+
5983+
// #7475
5984+
valueFlowUninit("struct S {\n"
5985+
" int a, b, c;\n"
5986+
"} typedef s_t;\n"
5987+
"void f() {\n"
5988+
" s_t s;\n"
5989+
" printf(\"%d\", s.a);\n"
5990+
"}\n");
5991+
ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: s.a\n", errout.str());
59715992
}
59725993

59735994
void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value

test/testunusedvar.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,14 @@ class TestUnusedVar : public TestFixture {
16401640
"\n"
16411641
"input.skip(sizeof(struct Header));");
16421642
ASSERT_EQUALS("", errout.str());
1643+
1644+
checkStructMemberUsage("struct S { int a, b, c; };\n" // #6561
1645+
"int f(FILE * fp) {\n"
1646+
" S s;\n"
1647+
" ::fread(&s, sizeof(S), 1, fp);\n"
1648+
" return s.b;\n"
1649+
"}\n");
1650+
ASSERT_EQUALS("", errout.str());
16431651
}
16441652

16451653
void structmember16() {

0 commit comments

Comments
 (0)