Uninitialized variables: Fixed false negative. Ticket: #2207

This commit is contained in:
Daniel Marjamäki 2010-11-16 20:01:57 +01:00
parent 77a5d4e399
commit cbdae275ed
2 changed files with 8 additions and 11 deletions

View File

@ -465,7 +465,7 @@ private:
}
// Used..
if (Token::Match(tok.previous(), "[[(,+-*/] %var% []),+-*/]"))
if (Token::Match(tok.previous(), "[[(,+-*/] %var% []),;+-*/]"))
{
use(checks, &tok);
return &tok;

View File

@ -66,6 +66,13 @@ private:
void uninitvar1()
{
// Ticket #2207 - False negative
checkUninitVar("void foo() {\n"
" int a;\n"
" b = c - a;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str());
// dereferencing uninitialized pointer..
checkUninitVar("static void foo()\n"
"{\n"
@ -546,16 +553,6 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
// Ticket #2207 - False negative
checkUninitVar("void foo(int x) {\n"
" int a;\n"
" if (x)\n"
" a = 1;\n"
" b = c - a;\n"
"}\n");
TODO_ASSERT_EQUALS("[test.cpp:5] (error) uninitialized variable a", errout.str());
ASSERT_EQUALS("", errout.str());
// Ticket #2207 - False positive
checkUninitVar("void foo(int x) {\n"
" int a;\n"