Uninitialized struct: Fixed false positive in for loop
This commit is contained in:
parent
1fd78d2b56
commit
4ac5648656
|
@ -1407,8 +1407,12 @@ bool CheckUninitVar::checkIfForWhileHead(const Token *startparentheses, const Va
|
|||
for (const Token *tok = startparentheses->next(); tok && tok != endpar; tok = tok->next()) {
|
||||
if (tok->varId() == var.varId()) {
|
||||
if (Token::Match(tok, "%var% . %var%")) {
|
||||
if (tok->strAt(2) == membervar)
|
||||
if (tok->strAt(2) == membervar) {
|
||||
if (tok->strAt(3) == "=")
|
||||
return true;
|
||||
else
|
||||
uninitStructMemberError(tok, tok->str() + "." + membervar);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -2662,6 +2662,13 @@ private:
|
|||
" if (fred.b == 0) { }\n"
|
||||
"}\n", "test.c", true);
|
||||
ASSERT_EQUALS("[test.c:9]: (error) Uninitialized struct member: fred.b\n", errout.str());
|
||||
|
||||
checkUninitVar2("struct S { int n; int m; };\n"
|
||||
"void f(void) {\n"
|
||||
" struct S s;\n"
|
||||
" for (s.n = 0; s.n <= 10; s.n++) { }\n"
|
||||
"}", "test.c");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void uninitvar2_while() {
|
||||
|
|
Loading…
Reference in New Issue