diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index f0172e71e..8ef950f6e 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -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; diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 7cf3f6c84..7e1a98f6b 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -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() {