Fixed #1182 (False positive: uninitialized variable 'int *pa = &a;')

This commit is contained in:
Daniel Marjamäki 2009-12-30 21:42:15 +01:00
parent 6c0919d9bd
commit 0ee3d7e46a
2 changed files with 10 additions and 1 deletions

View File

@ -1537,7 +1537,9 @@ private:
break;
if (Token::Match(tok2, "%var% ("))
break;
if (tok2->varId() && !Token::simpleMatch(tok2->next(), "="))
if (tok2->varId() &&
!Token::simpleMatch(tok2->previous(), "&") &&
!Token::simpleMatch(tok2->next(), "="))
use(foundError, checks, tok2);
}
}

View File

@ -1020,6 +1020,13 @@ private:
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n", errout.str());
checkUninitVar("void foo()\n"
"{\n"
" int x;\n"
" int *y = &x;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
checkUninitVar("static int foo()\n"
"{\n"
" int ret;\n"