Fixed #3058 (False positive: Uninitialized variable: data)
This commit is contained in:
parent
ef30da51bf
commit
0529654e37
|
@ -7072,6 +7072,19 @@ 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() &&
|
||||||
|
valueToken->str() == "&" &&
|
||||||
|
valueToken->next() &&
|
||||||
|
valueToken->next()->isName() &&
|
||||||
|
tok3->str() == valueToken->next()->str() &&
|
||||||
|
tok3->varId() > valueToken->next()->varId())
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Stop if label is found
|
// Stop if label is found
|
||||||
if (Token::Match(tok3, "; %type% : ;"))
|
if (Token::Match(tok3, "; %type% : ;"))
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -135,6 +135,7 @@ private:
|
||||||
TEST_CASE(simplifyKnownVariables40);
|
TEST_CASE(simplifyKnownVariables40);
|
||||||
TEST_CASE(simplifyKnownVariables41); // p=&x; if (p) ..
|
TEST_CASE(simplifyKnownVariables41); // p=&x; if (p) ..
|
||||||
TEST_CASE(simplifyKnownVariables42); // ticket #2031 - known string value after strcpy
|
TEST_CASE(simplifyKnownVariables42); // ticket #2031 - known string value after strcpy
|
||||||
|
TEST_CASE(simplifyKnownVariables43);
|
||||||
TEST_CASE(simplifyKnownVariablesBailOutAssign1);
|
TEST_CASE(simplifyKnownVariablesBailOutAssign1);
|
||||||
TEST_CASE(simplifyKnownVariablesBailOutAssign2);
|
TEST_CASE(simplifyKnownVariablesBailOutAssign2);
|
||||||
TEST_CASE(simplifyKnownVariablesBailOutFor1);
|
TEST_CASE(simplifyKnownVariablesBailOutFor1);
|
||||||
|
@ -2159,6 +2160,19 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void simplifyKnownVariables43()
|
||||||
|
{
|
||||||
|
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()
|
void simplifyKnownVariablesBailOutAssign1()
|
||||||
{
|
{
|
||||||
const char code[] = "int foo() {\n"
|
const char code[] = "int foo() {\n"
|
||||||
|
|
Loading…
Reference in New Issue