diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 5b49bd81f..c90e4f062 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -490,6 +490,17 @@ private: // Used.. if (Token::Match(tok.previous(), "[[(,+-*/|=] %var% ]|)|,|;|%op%")) { + // Taking address of array.. + std::list::const_iterator it; + for (it = checks.begin(); it != checks.end(); ++it) { + UninitVar *c = dynamic_cast(*it); + if (c && c->varId == tok.varId()) { + if (c->array) + bailOutVar(checks, tok.varId()); + break; + } + } + // initialize reference variable if (Token::Match(tok.tokAt(-3), "& %var% =")) bailOutVar(checks, tok.varId()); diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index b6fb246d5..30d606542 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -66,7 +66,7 @@ private: tokenizer.tokenize(istr, "test.cpp"); tokenizer.simplifyTokenList(); - // Check for redundant code.. + // Check code.. CheckUninitVar check(&tokenizer, &settings, this); check.executionPaths(); } @@ -1146,6 +1146,16 @@ private: " return header[0];\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + checkUninitVar("void f() {\n" + " ABC abc;\n" + " int a[1];\n" + "\n" + " abc.a = a;\n" + " init(&abc);\n" + " return a[0];\n" + "}"); + ASSERT_EQUALS("", errout.str()); } // alloc..