diff --git a/lib/token.cpp b/lib/token.cpp index 3670fb7ec..205bfaf53 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -1746,10 +1746,7 @@ void Token::printValueFlow(bool xml, std::ostream &out) const out << "<="; switch (value.valueType) { 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; case ValueFlow::Value::ValueType::TOK: out << value.tokvalue->str(); diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index de78c2c12..d4f971347 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -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) { - if (valueType.pointer) + if (valueType.pointer || value.isImpossible()) setTokenValue(parent,value,settings); else if (valueType.type == ValueType::Type::CHAR) 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()) { if (tok->hasKnownIntValue()) continue; - if (astIsUnsigned(tok)) { + if (astIsUnsigned(tok) && !astIsPointer(tok)) { std::vector minvalue = minUnsignedValue(tok); if (minvalue.empty()) continue; diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 92287c6c3..935be5156 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -835,6 +835,12 @@ private: "}"; 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" " bool a = (4 == 3);\n" " bool b = (3 == 3);\n"