Fix 10624: FP knownConditionTrueFalse with pointer member and dynamic cast (#3598)

This commit is contained in:
Paul Fultz II 2021-12-04 01:54:24 -06:00 committed by GitHub
parent a0d633945e
commit c14920218c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

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

View File

@ -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<Derived*>(PObj);\n"
" if (pD) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void alwaysTrueInfer() {