Fixed #3497 (False positive: Uninitialized variable)

This commit is contained in:
Daniel Marjamäki 2012-01-21 20:42:41 +01:00
parent 36479499e7
commit b8faee9d30
2 changed files with 14 additions and 1 deletions

View File

@ -474,7 +474,13 @@ private:
if (tok.varId()) {
// array variable passed as function parameter..
if (Token::Match(tok.previous(), "[(,] %var% [+-,)]")) {
if (Token::Match(tok.previous(), "( %var% ) )| ="))
// skip ')'..
const Token *tok2 = tok.next();
while (tok2 && tok2->str() == ")")
tok2 = tok2->next();
// variable is assigned like: "( %var% ) .. ="
if (Token::Match(tok.previous(), "( %var% )") && tok2 && tok2->str() == "=")
ExecutionPath::bailOutVar(checks, tok.varId());
else
use(checks, &tok);

View File

@ -1139,6 +1139,13 @@ private:
" return header[0];\n"
"}\n");
ASSERT_EQUALS("", errout.str());
checkUninitVar("void f() {\n" // Ticket #3497
" char header[1];\n"
" *((unsigned char*)((unsigned char *)(header))) = 0xff;\n"
" return header[0];\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
// alloc..