diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index e32400738..65c1da3b5 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1218,6 +1218,10 @@ const Token* CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, // * Passing address in RHS to pointer variable { const Token *tok = derefValue ? derefValue : valueExpr; + if (alloc == NO_ALLOC) { + while (tok->valueType() && tok->valueType()->pointer == 0 && Token::simpleMatch(tok->astParent(), ".")) + tok = tok->astParent(); + } if (Token::simpleMatch(tok->astParent(), "=")) { if (astIsLhs(tok)) return nullptr; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 5acb6289c..443a7ec25 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -3516,6 +3516,15 @@ private: "}\n", "test.c"); ASSERT_EQUALS("", errout.str()); + checkUninitVar("struct Cstring { char *text; int size, alloc; };\n" + "int maybe();\n" + "void f() {\n" + " Cstring res;\n" + " if ( ! maybe() ) return;\n" // <- fp goes away if this is removed + " ( ((res).text = (void*)0), ((res).size = (res).alloc = 0) );\n" // <- fp goes away if parentheses are removed + "}"); + ASSERT_EQUALS("", errout.str()); + { const char argDirectionsTestXmlData[] = "\n" "\n"