Fixed #8299 (false negative: uninitialized struct member)
This commit is contained in:
parent
271acf8aee
commit
c37b8ea55c
|
@ -673,6 +673,8 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
|
||||||
if (!membervar.empty()) {
|
if (!membervar.empty()) {
|
||||||
if (!suppressErrors && Token::Match(tok, "%name% . %name% ;|%cop%") && tok->strAt(2) == membervar)
|
if (!suppressErrors && Token::Match(tok, "%name% . %name% ;|%cop%") && tok->strAt(2) == membervar)
|
||||||
uninitStructMemberError(tok, tok->str() + "." + membervar);
|
uninitStructMemberError(tok, tok->str() + "." + membervar);
|
||||||
|
else if (mTokenizer->isCPP() && !suppressErrors && Token::Match(tok, "%name% ;"))
|
||||||
|
uninitStructMemberError(tok, tok->str() + "." + membervar);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use variable
|
// Use variable
|
||||||
|
|
|
@ -758,7 +758,8 @@ private:
|
||||||
" return ab;\n"
|
" return ab;\n"
|
||||||
"}";
|
"}";
|
||||||
checkUninitVar(code2, "test.cpp");
|
checkUninitVar(code2, "test.cpp");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized struct member: ab.a\n"
|
||||||
|
"[test.cpp:4]: (error) Uninitialized struct member: ab.b\n", errout.str());
|
||||||
checkUninitVar(code2, "test.c");
|
checkUninitVar(code2, "test.c");
|
||||||
ASSERT_EQUALS("[test.c:4]: (error) Uninitialized variable: ab\n", errout.str());
|
ASSERT_EQUALS("[test.c:4]: (error) Uninitialized variable: ab\n", errout.str());
|
||||||
|
|
||||||
|
@ -3511,6 +3512,14 @@ private:
|
||||||
"}\n", "test.c");
|
"}\n", "test.c");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar("struct S { int a; int b; };\n" // #8299
|
||||||
|
"void f(void) {\n"
|
||||||
|
" struct S s;\n"
|
||||||
|
" s.a = 0;\n"
|
||||||
|
" return s;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized struct member: s.b\n", errout.str());
|
||||||
|
|
||||||
// checkIfForWhileHead
|
// checkIfForWhileHead
|
||||||
checkUninitVar("struct FRED {\n"
|
checkUninitVar("struct FRED {\n"
|
||||||
" int a;\n"
|
" int a;\n"
|
||||||
|
|
Loading…
Reference in New Issue