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,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:

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

View File

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