Fix 10460: FP knownConditionTrueFalse 'fabs(x)<1/(double)16' is always false (#3445)

This commit is contained in:
Paul Fultz II 2021-09-05 00:10:58 -05:00 committed by GitHub
parent 2a8b4ae7dc
commit ccb31d8510
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -945,6 +945,13 @@ static void setTokenValueCast(Token *parent, const ValueType &valueType, const V
setTokenValue(parent, castValue(value, valueType.sign, settings->long_bit), settings); setTokenValue(parent, castValue(value, valueType.sign, settings->long_bit), settings);
else if (valueType.type == ValueType::Type::LONGLONG) else if (valueType.type == ValueType::Type::LONGLONG)
setTokenValue(parent, castValue(value, valueType.sign, settings->long_long_bit), settings); setTokenValue(parent, castValue(value, valueType.sign, settings->long_long_bit), settings);
else if (valueType.isFloat()) {
ValueFlow::Value floatValue = value;
floatValue.valueType = ValueFlow::Value::ValueType::FLOAT;
if (value.isIntValue())
floatValue.floatValue = value.intvalue;
setTokenValue(parent, floatValue, settings);
}
else if (value.isIntValue()) { else if (value.isIntValue()) {
const long long charMax = settings->signedCharMax(); const long long charMax = settings->signedCharMax();
const long long charMin = settings->signedCharMin(); const long long charMin = settings->signedCharMin();

View File

@ -519,6 +519,8 @@ private:
ASSERT_EQUALS((int)('\n'), valueOfTok("x='\\n';", "'\\n'").intvalue); ASSERT_EQUALS((int)('\n'), valueOfTok("x='\\n';", "'\\n'").intvalue);
TODO_ASSERT_EQUALS( TODO_ASSERT_EQUALS(
0xFFFFFFFF00000000, -1, valueOfTok("x=0xFFFFFFFF00000000;", "0xFFFFFFFF00000000").intvalue); // #7701 0xFFFFFFFF00000000, -1, valueOfTok("x=0xFFFFFFFF00000000;", "0xFFFFFFFF00000000").intvalue); // #7701
ASSERT_EQUALS_DOUBLE(16, valueOfTok("x=(double)16;", "(").floatValue, 1e-5);
ASSERT_EQUALS_DOUBLE(0.0625, valueOfTok("x=1/(double)16;", "/").floatValue, 1e-5);
// scope // scope
{ {