diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 59f66acf9..998d45bc3 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1141,12 +1141,10 @@ const Token* CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, return nullptr; // FIXME handle address of!! - if (valueExpr->astParent()->isUnaryOp("&")) - return nullptr; if (derefValue && derefValue->astParent() && derefValue->astParent()->isUnaryOp("&")) return nullptr; - // BAILOUT for binary & + // BAILOUT for binary & without parent if (Token::simpleMatch(valueExpr->astParent(), "&") && astIsRhs(valueExpr) && Token::Match(valueExpr->astParent()->tokAt(-3), "( %name% ) &")) return nullptr; @@ -1183,7 +1181,14 @@ const Token* CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, const int use = isFunctionParUsage(derefValue, false, NO_ALLOC, indirect); return (use>0) ? derefValue : nullptr; } - + if (valueExpr->astParent()->isUnaryOp("&")) { + const Token *parent = valueExpr->astParent(); + if (Token::Match(parent->astParent(), "[(,]") && (parent->astParent()->str() == "," || astIsRhs(parent))) { + const int use = isFunctionParUsage(valueExpr, pointer, alloc, indirect); + return (use>0) ? valueExpr : nullptr; + } + return nullptr; + } // Assignments; // * Is this LHS in assignment diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 470b708cc..b819c4856 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -3055,7 +3055,7 @@ private: " char c;\n" " a(&c);\n" "}"); - // FN ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: c\n", errout.str()); + ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: c\n", errout.str()); // pointer variable checkUninitVar("void a(char c);\n" // value => error @@ -3065,13 +3065,6 @@ private: "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: c\n", errout.str()); - checkUninitVar("void a(const char *c);\n" // const value => error - "void b() {\n" - " char c;\n" - " a(&c);\n" - "}"); - // FN ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: c\n", errout.str()); - checkUninitVar("void a(char *c);\n" // address => error "void b() {\n"