From 7d9fdf582b8bc92048e81173b2349ccf7b8d8cac Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sun, 1 Aug 2021 03:10:11 -0500 Subject: [PATCH] Fix 10121: False positive: Condition 'ab->a!=123' is always false when modifying an alias (#3293) --- lib/valueflow.cpp | 2 +- test/testcondition.cpp | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 4c3b8c058..b0e9aad57 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -2428,7 +2428,7 @@ struct ExpressionAnalyzer : SingleValueFlowAnalyzer { return; visitAstNodes(start, [&](const Token* tok) { for (const ValueFlow::Value& v : tok->values()) { - if (!v.isLocalLifetimeValue()) + if (!(v.isLocalLifetimeValue() || (astIsPointer(tok) && v.isSymbolicValue() && v.isKnown()))) continue; if (!v.tokvalue) continue; diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 7bbfbfbd9..4c93dbe2c 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -3642,6 +3642,27 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + // #10121 + check("struct AB {\n" + " int a;\n" + "};\n" + "struct ABC {\n" + " AB* ab;\n" + "};\n" + "void g(ABC*);\n" + "int f(struct ABC *abc) {\n" + " int err = 0;\n" + " AB *ab = abc->ab;\n" + " if (ab->a == 123){\n" + " g(abc);\n" + " if (ab->a != 123) {\n" + " err = 1;\n" + " }\n" + " }\n" + " return err;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + // #10323 check("void foo(int x) {\n" " if(x)\n"