Fixed #5660 (false positive: (error) Uninitialized variable: result)

This commit is contained in:
Daniel Marjamäki 2014-04-10 06:40:53 +02:00
parent 59cd1879db
commit 9b1d058410
2 changed files with 14 additions and 1 deletions

View File

@ -350,7 +350,12 @@ void ExecutionPath::checkScope(const Token *tok, std::list<ExecutionPath *> &che
return;
}
tok = tok->next()->link();
const Token * const end = tok->next()->link();
while (tok && tok != end) {
if (Token::Match(tok, "[{,] & %var% [,}]"))
ExecutionPath::bailOutVar(checks, tok->tokAt(2)->varId());
tok = tok->next();
}
if (!tok) {
ExecutionPath::bailOut(checks);
return;

View File

@ -1620,6 +1620,14 @@ private:
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: i\n", errout.str());
}
// Ticket #5660 - False positive
checkUninitVar("int f() {\n"
" int result;\n"
" int *res[] = {&result};\n"
" foo(res);\n"
" return result;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
// strncpy doesn't always null-terminate..