Fixed #3497 (False positive: Uninitialized variable)

This commit is contained in:
Daniel Marjamäki 2012-01-13 07:26:56 +01:00
parent e43fa83aa4
commit 47716ee4ca
2 changed files with 8 additions and 1 deletions

View File

@ -474,7 +474,7 @@ private:
if (tok.varId()) { if (tok.varId()) {
// array variable passed as function parameter.. // array variable passed as function parameter..
if (Token::Match(tok.previous(), "[(,] %var% [+-,)]")) { if (Token::Match(tok.previous(), "[(,] %var% [+-,)]")) {
if (Token::Match(tok.previous(), "( %var% ) =")) if (Token::Match(tok.previous(), "( %var% ) )| ="))
ExecutionPath::bailOutVar(checks, tok.varId()); ExecutionPath::bailOutVar(checks, tok.varId());
else else
use(checks, &tok); use(checks, &tok);

View File

@ -1132,6 +1132,13 @@ private:
" printf(\"%s\", a);\n" " printf(\"%s\", a);\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str());
checkUninitVar("void f() {\n" // Ticket #3497
" char header[1];\n"
" *((unsigned char*)(header)) = 0xff;\n"
" return header[0];\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
// alloc.. // alloc..