Fix issue 10225: false positive: knownConditionTrueFalse (#3196)
This commit is contained in:
parent
8034a70bd3
commit
f605f71e49
|
@ -1746,9 +1746,6 @@ void Token::printValueFlow(bool xml, std::ostream &out) const
|
||||||
out << "<=";
|
out << "<=";
|
||||||
switch (value.valueType) {
|
switch (value.valueType) {
|
||||||
case ValueFlow::Value::ValueType::INT:
|
case ValueFlow::Value::ValueType::INT:
|
||||||
if (tok->valueType() && tok->valueType()->sign == ValueType::UNSIGNED)
|
|
||||||
out << (MathLib::biguint)value.intvalue;
|
|
||||||
else
|
|
||||||
out << value.intvalue;
|
out << value.intvalue;
|
||||||
break;
|
break;
|
||||||
case ValueFlow::Value::ValueType::TOK:
|
case ValueFlow::Value::ValueType::TOK:
|
||||||
|
|
|
@ -840,7 +840,7 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
|
||||||
|
|
||||||
static void setTokenValueCast(Token *parent, const ValueType &valueType, const ValueFlow::Value &value, const Settings *settings)
|
static void setTokenValueCast(Token *parent, const ValueType &valueType, const ValueFlow::Value &value, const Settings *settings)
|
||||||
{
|
{
|
||||||
if (valueType.pointer)
|
if (valueType.pointer || value.isImpossible())
|
||||||
setTokenValue(parent,value,settings);
|
setTokenValue(parent,value,settings);
|
||||||
else if (valueType.type == ValueType::Type::CHAR)
|
else if (valueType.type == ValueType::Type::CHAR)
|
||||||
setTokenValue(parent, castValue(value, valueType.sign, settings->char_bit), settings);
|
setTokenValue(parent, castValue(value, valueType.sign, settings->char_bit), settings);
|
||||||
|
@ -1474,7 +1474,7 @@ static void valueFlowImpossibleValues(TokenList* tokenList, const Settings* sett
|
||||||
for (Token* tok = tokenList->front(); tok; tok = tok->next()) {
|
for (Token* tok = tokenList->front(); tok; tok = tok->next()) {
|
||||||
if (tok->hasKnownIntValue())
|
if (tok->hasKnownIntValue())
|
||||||
continue;
|
continue;
|
||||||
if (astIsUnsigned(tok)) {
|
if (astIsUnsigned(tok) && !astIsPointer(tok)) {
|
||||||
std::vector<MathLib::bigint> minvalue = minUnsignedValue(tok);
|
std::vector<MathLib::bigint> minvalue = minUnsignedValue(tok);
|
||||||
if (minvalue.empty())
|
if (minvalue.empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -835,6 +835,12 @@ private:
|
||||||
"}";
|
"}";
|
||||||
ASSERT_EQUALS(false, testValueOfX(code, 3U, 0));
|
ASSERT_EQUALS(false, testValueOfX(code, 3U, 0));
|
||||||
|
|
||||||
|
code = "bool f(const uint16_t * const p) {\n"
|
||||||
|
" const uint8_t x = (uint8_t)(*p & 0x01E0U) >> 5U;\n"
|
||||||
|
" return x != 0;\n"
|
||||||
|
"}\n";
|
||||||
|
ASSERT_EQUALS(true, testValueOfXImpossible(code, 3U, -1));
|
||||||
|
|
||||||
code = "bool f() {\n"
|
code = "bool f() {\n"
|
||||||
" bool a = (4 == 3);\n"
|
" bool a = (4 == 3);\n"
|
||||||
" bool b = (3 == 3);\n"
|
" bool b = (3 == 3);\n"
|
||||||
|
|
Loading…
Reference in New Issue