Fixed #3058 (False positive: Uninitialized variable: data)
This commit is contained in:
parent
477d1e92c9
commit
a96028b43b
|
@ -7075,13 +7075,36 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
|
|||
// Stop if there is a pointer alias and a shadow variable is
|
||||
// declared in an inner scope (#3058)
|
||||
if (valueIsPointer && tok3->varId() > 0 &&
|
||||
tok3->previous() && tok3->previous()->isName() &&
|
||||
tok3->previous() && (tok3->previous()->isName() || tok3->previous()->str() == "*") &&
|
||||
valueToken->str() == "&" &&
|
||||
valueToken->next() &&
|
||||
valueToken->next()->isName() &&
|
||||
tok3->str() == valueToken->next()->str() &&
|
||||
tok3->varId() > valueToken->next()->varId())
|
||||
{
|
||||
// more checking if this is a variable declaration
|
||||
bool decl = true;
|
||||
for (const Token *tok4 = tok3->previous(); tok4; tok4 = tok4->previous())
|
||||
{
|
||||
if (Token::Match(tok4, "[;{}]"))
|
||||
break;
|
||||
|
||||
else if (tok4->isName())
|
||||
{
|
||||
if (tok4->varId() > 0)
|
||||
{
|
||||
decl = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
else if (!Token::Match(tok4, "[&*]"))
|
||||
{
|
||||
decl = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (decl)
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -2161,6 +2161,7 @@ private:
|
|||
}
|
||||
|
||||
void simplifyKnownVariables43()
|
||||
{
|
||||
{
|
||||
const char code[] = "void f() {\n"
|
||||
" int a, *p; p = &a;\n"
|
||||
|
@ -2173,6 +2174,19 @@ private:
|
|||
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
|
||||
}
|
||||
|
||||
{
|
||||
const char code[] = "void f() {\n"
|
||||
" int *a, **p; p = &a;\n"
|
||||
" { int *a = *p; }\n"
|
||||
"}";
|
||||
const char expected[] = "void f ( ) {\n"
|
||||
"int * a ; int * * p ; p = & a ;\n"
|
||||
"{ int * a ; a = * p ; }\n"
|
||||
"}";
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
|
||||
}
|
||||
}
|
||||
|
||||
void simplifyKnownVariablesBailOutAssign1()
|
||||
{
|
||||
const char code[] = "int foo() {\n"
|
||||
|
|
Loading…
Reference in New Issue