diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 409693824..a69351727 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1549,7 +1549,7 @@ 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) + if (Token::Match(tok2,"[()] ( %type% *| ) &") && tok2->tokAt(2)->varId() == 0) return false; // cast while (tok2 && tok2->str() == "(") tok2 = tok2->previous(); diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 15d03dbf7..b1ad18d24 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -2023,6 +2023,12 @@ private: "}", "test.c", false); ASSERT_EQUALS("", errout.str()); + checkUninitVar2("void f() {\n" // #4737 - weird cast. + " int x;\n" + " do_something(&((char*)&x)[0], 1);\n" + "}"); + ASSERT_EQUALS("", errout.str()); + // using uninit var in condition checkUninitVar2("void f(void) {\n" " int x;\n"