ValueFlow: Improved value for cast
This commit is contained in:
parent
606bb78297
commit
44ccbdedec
|
@ -323,6 +323,9 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
|
|||
setTokenValue(parent, castValue(value, valueType.sign, settings->long_bit), settings);
|
||||
else if (valueType.type == ValueType::Type::LONGLONG)
|
||||
setTokenValue(parent, castValue(value, valueType.sign, settings->long_long_bit), settings);
|
||||
else if (value.isIntValue() && value.intvalue < (1 << (settings->char_bit - 1)) && value.intvalue > -(1 << (settings->char_bit - 1)))
|
||||
// unknown type, but value is small so there should be no truncation etc
|
||||
setTokenValue(parent,value,settings);
|
||||
}
|
||||
|
||||
else if (parent->str() == ":") {
|
||||
|
|
|
@ -377,7 +377,8 @@ private:
|
|||
ASSERT_EQUALS(0, valueOfTok("3 < (a ? b : 2);", "<").intvalue);
|
||||
ASSERT_EQUALS(0, valueOfTok("3 <= (a ? b : 2);", "<=").intvalue);
|
||||
|
||||
ASSERT(tokenValues("(UNKNOWN_TYPE)123;","(").empty());
|
||||
ASSERT_EQUALS(1, valueOfTok("(UNKNOWN_TYPE)1;","(").intvalue);
|
||||
ASSERT(tokenValues("(UNKNOWN_TYPE)1000;","(").empty()); // don't know if there is truncation, sign extension
|
||||
ASSERT_EQUALS(255, valueOfTok("(unsigned char)~0;", "(").intvalue);
|
||||
ASSERT_EQUALS(0, valueOfTok("(int)0;", "(").intvalue);
|
||||
ASSERT_EQUALS(0, valueOfTok("(UNKNOWN_TYPE*)0;","(").intvalue);
|
||||
|
|
Loading…
Reference in New Issue