Fixed #2196 (False positive: Invalid data is allocated but not initialized (initialization in loop))

This commit is contained in:
Daniel Marjamäki 2010-11-13 10:33:35 +01:00
parent a06a1a6574
commit bf15236b9e
2 changed files with 9 additions and 1 deletions

View File

@ -677,7 +677,7 @@ private:
} }
// it is possible that the variable is initialized here // it is possible that the variable is initialized here
if (Token::Match(tok2->previous(), "[(,] %var% [,)]")) if (Token::Match(tok2->previous(), "[(,] %var% [+-,)]"))
bailouts.insert(tok2->varId()); bailouts.insert(tok2->varId());
// array initialization.. // array initialization..

View File

@ -1178,6 +1178,14 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: f\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: f\n", errout.str());
checkUninitVar("void f()\n"
"{\n"
" char *p = malloc(10);\n"
" read(p + 1);\n"
" return p;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
checkUninitVar("void f()\n" checkUninitVar("void f()\n"
"{\n" "{\n"
" Abc *p;\n" " Abc *p;\n"