diff --git a/lib/vf_analyzers.cpp b/lib/vf_analyzers.cpp index cfba7d5f970..6ebd5adf9f7 100644 --- a/lib/vf_analyzers.cpp +++ b/lib/vf_analyzers.cpp @@ -616,6 +616,8 @@ struct ValueFlowAnalyzer : Analyzer { return Action::None; Action la = analyzeLifetime(lifeTok); if (la.matches()) { + if (tok->isUnaryOp("*") && tok->valueType() && lifeTok->valueType() && tok->valueType()->pointer < lifeTok->valueType()->pointer) + return Action::Invalid; Action a = Action::Read; if (isModified(tok).isModified()) a = Action::Invalid; diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 888710ce57d..886d1058190 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -9092,6 +9092,15 @@ class TestValueFlow : public TestFixture { " return x;\n" "}\n"; ASSERT_EQUALS(false, testValueOfX(code, 3U, "malloc(10)", 0)); + + code = "struct S {\n" // #14891 + " void f() const {\n" + " const int* p = a;\n" + " if (*p) {}\n" + " }\n" + " int a[3];\n" + "};\n"; + ASSERT(tokenValues(code, "* p )").empty()); } void valueFlowSymbolicIdentity()