Fixed #3666 (False positive: Uninitialized variable (taking address))

This commit is contained in:
Daniel Marjamäki 2012-03-16 17:28:05 +01:00
parent 0340764726
commit 2757229064
2 changed files with 22 additions and 1 deletions

View File

@ -490,6 +490,17 @@ private:
// Used..
if (Token::Match(tok.previous(), "[[(,+-*/|=] %var% ]|)|,|;|%op%")) {
// Taking address of array..
std::list<ExecutionPath *>::const_iterator it;
for (it = checks.begin(); it != checks.end(); ++it) {
UninitVar *c = dynamic_cast<UninitVar *>(*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());

View File

@ -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..