Fixed #7135 (ValueFlow: Wrong pointer alias set for 'p = &p[x];')

This commit is contained in:
Daniel Marjamäki 2015-11-15 23:38:23 +01:00
parent 6cf7ff4243
commit 04ecbba361
2 changed files with 17 additions and 1 deletions

View File

@ -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;

View File

@ -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() {