Uninitialized variables: Fix FP for struct array

This commit is contained in:
Daniel Marjamäki 2015-09-16 14:42:55 +02:00
parent 66f1d9d680
commit 305760f143
2 changed files with 10 additions and 1 deletions

View File

@ -849,7 +849,7 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, Alloc al
return true;
} else if (alloc != NO_ALLOC && Token::Match(vartok, "%var% [")) {
const Token *parent = vartok->next()->astParent();
while (Token::simpleMatch(parent, "["))
while (Token::Match(parent, "[|."))
parent = parent->astParent();
if (Token::simpleMatch(parent, "&") && !parent->astOperand2())
return false;

View File

@ -1435,6 +1435,15 @@ private:
" bar(x);\n"
"}");
ASSERT_EQUALS("", errout.str());
// struct
checkUninitVar("struct Fred { int x; int y; };\n"
""
"void f() {\n"
" struct Fred fred[10];\n"
" fred[1].x = 0;\n"
"}", "test.c");
ASSERT_EQUALS("", errout.str());
}
void uninitvar_pointertoarray() {