Fixed #7135 (ValueFlow: Wrong pointer alias set for 'p = &p[x];')
This commit is contained in:
parent
6cf7ff4243
commit
04ecbba361
|
@ -703,7 +703,16 @@ static void valueFlowPointerAlias(TokenList *tokenlist)
|
|||
continue;
|
||||
|
||||
// child should be some buffer or variable
|
||||
if (!Token::Match(tok->astOperand1(), "%name%|.|[|;"))
|
||||
const Token *vartok = tok->astOperand1();
|
||||
while (vartok) {
|
||||
if (vartok->str() == "[")
|
||||
vartok = vartok->astOperand1();
|
||||
else if (vartok->str() == "." || vartok->str() == "::")
|
||||
vartok = vartok->astOperand2();
|
||||
else
|
||||
break;
|
||||
}
|
||||
if (!(vartok && vartok->variable() && !vartok->variable()->isPointer()))
|
||||
continue;
|
||||
|
||||
ValueFlow::Value value;
|
||||
|
|
|
@ -209,6 +209,13 @@ private:
|
|||
" *x = 0;\n" // <- x can point at i
|
||||
"}";
|
||||
ASSERT_EQUALS(true, testValueOfX(code, 4, "& i"));
|
||||
|
||||
code = "void f() {\n"
|
||||
" struct X *x;\n"
|
||||
" x = &x[1];\n"
|
||||
"}";
|
||||
ASSERT_EQUALS(true, tokenValues(code, "&").empty());
|
||||
ASSERT_EQUALS(true, tokenValues(code, "x [").empty());
|
||||
}
|
||||
|
||||
void valueFlowArrayElement() {
|
||||
|
|
Loading…
Reference in New Issue