Fix issue 10225: false positive: knownConditionTrueFalse (#3196)

This commit is contained in:
Paul Fultz II 2021-04-05 03:20:14 -05:00 committed by GitHub
parent 8034a70bd3
commit f605f71e49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 6 deletions

View File

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

View File

@ -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<MathLib::bigint> minvalue = minUnsignedValue(tok);
if (minvalue.empty())
continue;

View File

@ -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"