Skip to content

Commit 1bc0317

Browse files
Fix #11002 FP uninitStructMember with extra parentheses (#4047)
1 parent b4df064 commit 1bc0317

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

lib/checkuninitvar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1461,7 +1461,7 @@ bool CheckUninitVar::isMemberVariableUsage(const Token *tok, bool isPointer, All
14611461
if (parent && parent->isUnaryOp("&"))
14621462
return false;
14631463
return true;
1464-
} else if (!isPointer && Token::Match(tok->previous(), "[(,] %name% [,)]") && isVariableUsage(tok, isPointer, alloc))
1464+
} else if (!isPointer && !Token::simpleMatch(tok->astParent(), ".") && Token::Match(tok->previous(), "[(,] %name% [,)]") && isVariableUsage(tok, isPointer, alloc))
14651465
return true;
14661466

14671467
else if (!isPointer && Token::Match(tok->previous(), "= %name% ;"))

test/testuninitvar.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4132,6 +4132,15 @@ class TestUninitVar : public TestFixture {
41324132
" x = a.m;\n"
41334133
"}");
41344134
ASSERT_EQUALS("", errout.str());
4135+
4136+
// #11002
4137+
checkUninitVar("struct S { char *p; int len; };\n"
4138+
"void f() {\n"
4139+
" S s;\n"
4140+
" s.p = nullptr;\n"
4141+
" char* q = (s).p;\n"
4142+
"}\n");
4143+
ASSERT_EQUALS("", errout.str());
41354144
}
41364145

41374146
void uninitvar2_while() {

0 commit comments

Comments
 (0)