diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 3ae3c9a2f..90fd1f537 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1693,9 +1693,9 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool all return true; if (Token::Match(argStart, "const %type% & %var% [,)]")) return true; - if (pointer && !address && Token::Match(argStart, "%type% * %var% [,)]")) + if (pointer && !address && Token::Match(argStart, "struct| %type% * %var% [,)]")) return true; - if ((pointer || address) && Token::Match(argStart, "const %type% * %var% [,)]")) + if ((pointer || address) && Token::Match(argStart, "const struct| %type% * %var% [,)]")) return true; if ((pointer || address) && Token::Match(argStart, "const %type% %var% [") && Token::Match(argStart->linkAt(3), "] [,)]")) return true; @@ -1830,7 +1830,7 @@ bool CheckUninitVar::isMemberVariableUsage(const Token *tok, bool isPointer, boo if (Token::Match(tok, "%var% . %var%") && tok->strAt(2) == membervar) return true; - else if (Token::Match(tok->previous(), "[(,] %var% [,)]") && isVariableUsage(tok, isPointer, alloc, _tokenizer->isCPP())) + else if (!isPointer && Token::Match(tok->previous(), "[(,] %var% [,)]") && isVariableUsage(tok, isPointer, alloc, _tokenizer->isCPP())) return true; return false; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 744f768d9..565b0f0ac 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -2649,6 +2649,14 @@ private: "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: c\n", errout.str()); + checkUninitVar2("typedef struct { int a; int b; } AB;\n" + "void a(AB *ab);\n" + "void b() {\n" + " AB *ab;\n" + " a(ab);\n" + "}"); + ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: ab\n", errout.str()); + checkUninitVar2("void a(const char *c);\n" // const address => error "void b() {\n" " char *c;\n"