diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 4273a0844..a4ed4649c 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -774,7 +774,7 @@ private: const Token *tok2 = tok.next(); while (Token::Match(tok2, ". %var%")) tok2 = tok2->tokAt(2); - if (tok2 && tok2->str() != "=") + if (tok2 && tok2->str() != "=" && tok.strAt(-1) != "&") use_pointer(checks, &tok); else bailOutVar(checks, tok.varId()); diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index a079b7fd0..1343a8cba 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -942,6 +942,13 @@ private: "};\n"); ASSERT_EQUALS("", errout.str()); + checkUninitVar("void f()\n" + "{\n" + " Fred *fred = malloc(sizeof(Fred));\n" + " x(&fred->f);\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + checkUninitVar("void foo(char *s)\n" "{\n" " char *a = malloc(100);\n"