ValueFlow: Fix uninitvar false positive after initialization '*((int*)&x) = ..' (#5142)
This commit is contained in:
parent
3c8caac772
commit
1c28457d2c
|
@ -7924,6 +7924,14 @@ static Token* findStartToken(const Variable* var, Token* start, const Library* l
|
|||
Token* first = uses.front();
|
||||
if (Token::findmatch(start, "goto|asm|setjmp|longjmp", first))
|
||||
return start;
|
||||
if (first != var->nameToken()) {
|
||||
// if this is lhs in assignment then set first to the first token in LHS expression
|
||||
Token* temp = first;
|
||||
while (Token::Match(temp->astParent(), "[&*(]") && precedes(temp->astParent(), temp))
|
||||
temp = temp->astParent();
|
||||
if (Token::simpleMatch(temp->astParent(), "=") && precedes(temp, temp->astParent()))
|
||||
first = temp;
|
||||
}
|
||||
// If there is only one usage
|
||||
if (uses.size() == 1)
|
||||
return first->previous();
|
||||
|
|
|
@ -5292,6 +5292,18 @@ private:
|
|||
"}";
|
||||
ASSERT_EQUALS(0U, tokenValues(code, "x )").size());
|
||||
|
||||
// initialization
|
||||
code = "int foo() {\n"
|
||||
" int x;\n"
|
||||
" *((int *)(&x)) = 12;"
|
||||
" a = x + 1;\n"
|
||||
"}";
|
||||
values = tokenValues(code, "x +");
|
||||
ASSERT_EQUALS(true, values.empty());
|
||||
// ASSERT_EQUALS(1U, values.size());
|
||||
// ASSERT(values.front().isIntValue());
|
||||
// ASSERT_EQUALS(12, values.front().intvalue);
|
||||
|
||||
// #8036
|
||||
code = "void foo() {\n"
|
||||
" int x;\n"
|
||||
|
|
Loading…
Reference in New Issue