diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 51666003f..fb51da8f2 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1534,6 +1534,8 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool cpp return false; // address of if (tok2 && tok2->str() == ")") tok2 = tok2->link()->previous(); + if (Token::Match(tok2,") ( %type% *| ) &") && tok2->tokAt(2)->varId() == 0) + return false; // cast while (tok2 && tok2->str() == "(") tok2 = tok2->previous(); while (tok2 && tok2->str() == "*") diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index bb80459fa..d8abfd897 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -2344,6 +2344,12 @@ private: " if (&a == &b);\n" "}"); ASSERT_EQUALS("", errout.str()); + + checkUninitVar2("void f() {\n" // #4439 - cast address of uninitialized variable + " int a;\n" + " x((A)(B)&a);\n" + "}"); + ASSERT_EQUALS("", errout.str()); } // #3869 - reference variable