Skip to content

Commit 305760f

Browse files
committed
Uninitialized variables: Fix FP for struct array
1 parent 66f1d9d commit 305760f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/checkuninitvar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, Alloc al
849849
return true;
850850
} else if (alloc != NO_ALLOC && Token::Match(vartok, "%var% [")) {
851851
const Token *parent = vartok->next()->astParent();
852-
while (Token::simpleMatch(parent, "["))
852+
while (Token::Match(parent, "[|."))
853853
parent = parent->astParent();
854854
if (Token::simpleMatch(parent, "&") && !parent->astOperand2())
855855
return false;

test/testuninitvar.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,15 @@ class TestUninitVar : public TestFixture {
14351435
" bar(x);\n"
14361436
"}");
14371437
ASSERT_EQUALS("", errout.str());
1438+
1439+
// struct
1440+
checkUninitVar("struct Fred { int x; int y; };\n"
1441+
""
1442+
"void f() {\n"
1443+
" struct Fred fred[10];\n"
1444+
" fred[1].x = 0;\n"
1445+
"}", "test.c");
1446+
ASSERT_EQUALS("", errout.str());
14381447
}
14391448

14401449
void uninitvar_pointertoarray() {

0 commit comments

Comments
 (0)