Fixed #1352 (false positive: uninitialized variable)

This commit is contained in:
Daniel Marjamäki 2010-02-06 16:51:32 +01:00
parent 70620b6f80
commit 0a31e5e3ee
2 changed files with 22 additions and 1 deletions

View File

@ -4382,7 +4382,8 @@ bool Tokenizer::simplifyKnownVariables()
--indentlevel3;
if (indentlevel3 < indentlevel)
{
if (Token::Match(tok2->tokAt(-3), "%var% = & %var% ;"))
if (Token::Match(tok2->tokAt(-7), "%type% * %var% ; %var% = & %var% ;") &&
tok2->tokAt(-5)->str() == tok2->tokAt(-3)->str())
{
tok2 = tok2->tokAt(-4);
Token::eraseTokens(tok2, tok2->tokAt(5));

View File

@ -175,6 +175,7 @@ private:
TEST_CASE(pointeralias1);
TEST_CASE(pointeralias2);
TEST_CASE(pointeralias3);
TEST_CASE(reduceConstness);
@ -3357,6 +3358,25 @@ private:
ASSERT_EQUALS(expected, tok(code));
}
void pointeralias3()
{
const char code[] = "void f()\n"
"{\n"
" int i, j, *p;\n"
" if (ab) p = &i;\n"
" else p = &j;\n"
" *p = 0;\n"
"}\n";
const char expected[] = "void f ( ) "
"{"
" int i ; int j ; int * p ;"
" if ( ab ) { p = & i ; }"
" else { p = & j ; }"
" * p = 0 ; "
"}";
ASSERT_EQUALS(expected, tok(code));
}
void reduceConstness()
{