diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 2cc9af969..e648252df 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1461,7 +1461,7 @@ bool CheckUninitVar::isMemberVariableUsage(const Token *tok, bool isPointer, All if (parent && parent->isUnaryOp("&")) return false; 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; else if (!isPointer && Token::Match(tok->previous(), "= %name% ;")) diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index aa4f1a1a4..7935f0d84 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -4132,6 +4132,15 @@ private: " x = a.m;\n" "}"); 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() {