Fixed #4497 (False positive: uninitialized struct (writing/reading member))
This commit is contained in:
parent
a1cbed3df8
commit
7c615f0f12
|
@ -1082,7 +1082,7 @@ void CheckUninitVar::checkScope(const Scope* scope)
|
|||
tok = tok->next();
|
||||
if (stdtype || i->isPointer())
|
||||
checkScopeForVariable(scope, tok, *i, NULL, NULL, NULL);
|
||||
if (_settings->experimental && Token::Match(i->typeStartToken(), "struct %type% %var% ;")) {
|
||||
if (Token::Match(i->typeStartToken(), "struct %type% %var% ;")) {
|
||||
const std::string structname(i->typeStartToken()->next()->str());
|
||||
const SymbolDatabase * symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||
for (std::size_t j = 0U; j < symbolDatabase->classAndStructScopes.size(); ++j) {
|
||||
|
@ -1156,7 +1156,7 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
|
|||
}
|
||||
|
||||
// initialization / usage in condition..
|
||||
if (!alwaysTrue && checkIfForWhileHead(scope, tok->next(), var, suppressErrors, bool(number_of_if == 0)))
|
||||
if (!alwaysTrue && checkIfForWhileHead(scope, tok->next(), var, suppressErrors || (membervar != NULL), bool(number_of_if == 0)))
|
||||
return true;
|
||||
|
||||
// checking if a not-zero variable is zero => bail out
|
||||
|
|
|
@ -2606,6 +2606,31 @@ private:
|
|||
" do_something(c);\n"
|
||||
"}\n", "test.c", true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// checkIfForWhileHead
|
||||
checkUninitVar2("struct FRED {\n"
|
||||
" int a;\n"
|
||||
" int b;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"void f(void) {\n"
|
||||
" struct FRED fred;\n"
|
||||
" fred.a = do_something();\n"
|
||||
" if (fred.a == 0) { }\n"
|
||||
"}\n", "test.c", true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar2("struct FRED {\n"
|
||||
" int a;\n"
|
||||
" int b;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"void f(void) {\n"
|
||||
" struct FRED fred;\n"
|
||||
" fred.a = do_something();\n"
|
||||
" if (fred.b == 0) { }\n"
|
||||
"}\n", "test.c", true);
|
||||
TODO_ASSERT_EQUALS("error", "", errout.str());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue