Fixed #3666 (False positive: Uninitialized variable (taking address))
This commit is contained in:
parent
0340764726
commit
2757229064
|
@ -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());
|
||||
|
|
|
@ -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..
|
||||
|
|
Loading…
Reference in New Issue