Fix #11002 FP uninitStructMember with extra parentheses (#4047)

This commit is contained in:
chrchr-github 2022-04-25 22:22:35 +02:00 committed by GitHub
parent b4df064875
commit 1bc0317719
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -1461,7 +1461,7 @@ bool CheckUninitVar::isMemberVariableUsage(const Token *tok, bool isPointer, All
if (parent && parent->isUnaryOp("&")) if (parent && parent->isUnaryOp("&"))
return false; return false;
return true; return true;
} else if (!isPointer && Token::Match(tok->previous(), "[(,] %name% [,)]") && isVariableUsage(tok, isPointer, alloc)) } else if (!isPointer && !Token::simpleMatch(tok->astParent(), ".") && Token::Match(tok->previous(), "[(,] %name% [,)]") && isVariableUsage(tok, isPointer, alloc))
return true; return true;
else if (!isPointer && Token::Match(tok->previous(), "= %name% ;")) else if (!isPointer && Token::Match(tok->previous(), "= %name% ;"))

View File

@ -4132,6 +4132,15 @@ private:
" x = a.m;\n" " x = a.m;\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// #11002
checkUninitVar("struct S { char *p; int len; };\n"
"void f() {\n"
" S s;\n"
" s.p = nullptr;\n"
" char* q = (s).p;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
void uninitvar2_while() { void uninitvar2_while() {