diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 90fd1f537..bfcc2ee5b 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, "struct| %type% * %var% [,)]")) + if (pointer && !address && !alloc && Token::Match(argStart, "struct| %type% * %var% [,)]")) return true; - if ((pointer || address) && Token::Match(argStart, "const struct| %type% * %var% [,)]")) + if ((pointer || address) && !alloc && 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; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 565b0f0ac..4378cdb8b 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -3278,6 +3278,14 @@ private: " return ab->a;\n" // error "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized struct member: ab.a\n", errout.str()); + + checkUninitVar2("struct AB { int a; int b; };\n" + "void do_something(struct AB *ab);\n" // unknown function + "int f() {\n" + " struct AB *ab = malloc(sizeof(struct AB));\n" + " do_something(ab);\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void syntax_error() { // Ticket #5073