Fix 9735 for valueFlowUninit (#3538)
This commit is contained in:
parent
7e2c993163
commit
ffc2a9d8e2
|
@ -565,12 +565,12 @@ static void setTokenValue(Token* tok, ValueFlow::Value value, const Settings* se
|
||||||
if (Token::Match(tok, ". %var%"))
|
if (Token::Match(tok, ". %var%"))
|
||||||
setTokenValue(tok->next(), value, settings);
|
setTokenValue(tok->next(), value, settings);
|
||||||
ValueFlow::Value pvalue = value;
|
ValueFlow::Value pvalue = value;
|
||||||
if (!value.subexpressions.empty()) {
|
if (!value.subexpressions.empty() && Token::Match(parent, ". %var%")) {
|
||||||
if (Token::Match(parent, ". %var%") && contains(value.subexpressions, parent->next()->str()))
|
if (contains(value.subexpressions, parent->next()->str()))
|
||||||
pvalue.subexpressions.clear();
|
pvalue.subexpressions.clear();
|
||||||
|
else
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (!pvalue.subexpressions.empty())
|
|
||||||
return;
|
|
||||||
if (parent->isUnaryOp("&")) {
|
if (parent->isUnaryOp("&")) {
|
||||||
pvalue.indirect++;
|
pvalue.indirect++;
|
||||||
setTokenValue(parent, pvalue, settings);
|
setTokenValue(parent, pvalue, settings);
|
||||||
|
|
|
@ -4517,26 +4517,27 @@ private:
|
||||||
|
|
||||||
void valueFlowUninit() {
|
void valueFlowUninit() {
|
||||||
// #9735 - FN
|
// #9735 - FN
|
||||||
ctu("typedef struct\n"
|
valueFlowUninit("typedef struct\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int x;\n"
|
" int x;\n"
|
||||||
" unsigned int flag : 1;\n"// bit filed gets never initialized
|
" unsigned int flag : 1;\n" // bit filed gets never initialized
|
||||||
"} status;\n"
|
"} status;\n"
|
||||||
"bool foo(const status * const s)\n"
|
"bool foo(const status * const s)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" return s->flag;\n"// << uninitvar
|
" return s->flag;\n" // << uninitvar
|
||||||
"}\n"
|
"}\n"
|
||||||
"void bar(const status * const s)\n"
|
"void bar(const status * const s)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" if( foo(s) == 1) {;}\n"
|
" if( foo(s) == 1) {;}\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"void f(void)\n"
|
"void f(void)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" status s;\n"
|
" status s;\n"
|
||||||
" s.x = 42;\n"
|
" s.x = 42;\n"
|
||||||
" bar(&s);\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());
|
ASSERT_EQUALS("[test.cpp:18] -> [test.cpp:12] -> [test.cpp:8]: (error) Uninitialized variable: s->flag\n",
|
||||||
|
errout.str());
|
||||||
|
|
||||||
// Ticket #2207 - False negative
|
// Ticket #2207 - False negative
|
||||||
valueFlowUninit("void foo() {\n"
|
valueFlowUninit("void foo() {\n"
|
||||||
|
|
Loading…
Reference in New Issue