From c14920218ccef15ef7aa3cf8dbbeb0b38d9d8bdc Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sat, 4 Dec 2021 01:54:24 -0600 Subject: [PATCH] Fix 10624: FP knownConditionTrueFalse with pointer member and dynamic cast (#3598) --- lib/valueflow.cpp | 2 +- test/testcondition.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 788a20bb7..df3632683 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -598,7 +598,7 @@ static void setTokenValue(Token* tok, ValueFlow::Value value, const Settings* se // cast.. if (const Token *castType = getCastTypeStartToken(parent)) { if (((tok->valueType() == nullptr && value.isImpossible()) || astIsPointer(tok)) && - value.valueType == ValueFlow::Value::ValueType::INT && + contains({ValueFlow::Value::ValueType::INT, ValueFlow::Value::ValueType::SYMBOLIC}, value.valueType) && Token::simpleMatch(parent->astOperand1(), "dynamic_cast")) return; const ValueType &valueType = ValueType::parseDecl(castType, settings); diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 59a85f084..29078d3ad 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -3914,6 +3914,19 @@ private: " if (m_PC->GetI() != I) {}\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // #10624 + check("struct Data {\n" + " Base* PBase{};\n" + "};\n" + "void f(Data* BaseData) {\n" + " Base* PObj = BaseData->PBase;\n" + " if (PObj == nullptr)\n" + " return;\n" + " Derived* pD = dynamic_cast(PObj);\n" + " if (pD) {}\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void alwaysTrueInfer() {