Uninitialized struct: Fixed false positive in for loop

This commit is contained in:
Daniel Marjamäki 2013-02-05 17:01:46 +01:00
parent 1fd78d2b56
commit 4ac5648656
2 changed files with 13 additions and 2 deletions

View File

@ -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)
uninitStructMemberError(tok, tok->str() + "." + membervar);
if (tok->strAt(2) == membervar) {
if (tok->strAt(3) == "=")
return true;
else
uninitStructMemberError(tok, tok->str() + "." + membervar);
}
continue;
}

View File

@ -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() {