testuninitvar: #9735 - Moved test to valueFlowUninit.

This commit is contained in:
orbitcowboy 2021-10-31 07:14:00 +01:00
parent 8c9c46835a
commit bd63882d80
1 changed files with 22 additions and 22 deletions

View File

@ -4516,6 +4516,28 @@ private:
}
void valueFlowUninit() {
// #9735 - FN
ctu("typedef struct\n"
"{\n"
" int x;\n"
" unsigned int flag : 1;\n"// bit filed gets never initialized
"} status;\n"
"bool foo(const status * const s)\n"
"{\n"
" return s->flag;\n"// << uninitvar
"}\n"
"void bar(const status * const s)\n"
"{\n"
" if( foo(s) == 1) {;}\n"
"}\n"
"void f(void)\n"
"{\n"
" status s;\n"
" s.x = 42;\n"
" bar(&s);\n"
"}");
ASSERT_EQUALS("[test.cpp:18] -> [test.cpp:12] -> [test.cpp:8]: (error) Using argument s that points at uninitialized variable s\n", errout.str());
// Ticket #2207 - False negative
valueFlowUninit("void foo() {\n"
" int a;\n"
@ -5946,28 +5968,6 @@ private:
}
void ctu() {
// #9735 - FN
ctu("typedef struct\n"
"{\n"
" int x;\n"
" unsigned int flag : 1;\n" // bit filed gets never initialized
"} status;\n"
"bool foo(const status * const s)\n"
"{\n"
" return s->flag;\n" // << uninitvar
"}\n"
"void bar(const status * const s)\n"
"{\n"
" if( foo(s) == 1) {;}\n"
"}\n"
"void f(void)\n"
"{\n"
" status s;\n"
" s.x = 42;\n"
" bar(&s);\n"
"}");
ASSERT_EQUALS("[test.cpp:18] -> [test.cpp:12] -> [test.cpp:8]: (error) Using argument s that points at uninitialized variable s\n", errout.str());
ctu("void f(int *p) {\n"
" a = *p;\n"
"}\n"