Fix 10289: ValueFlow; Wrong known value 'size_t - uint16_t > 0' (#3273)
This commit is contained in:
parent
8ad0905e3b
commit
ab50a75d8a
|
@ -431,6 +431,19 @@ static T calculate(const std::string& s, const T& x, const T& y)
|
||||||
/** Set token value for cast */
|
/** Set token value for cast */
|
||||||
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);
|
||||||
|
|
||||||
|
static bool isCompatibleValues(const ValueFlow::Value& value1, const ValueFlow::Value& value2)
|
||||||
|
{
|
||||||
|
if (value1.isKnown() || value2.isKnown())
|
||||||
|
return true;
|
||||||
|
if (value1.isImpossible() || value2.isImpossible())
|
||||||
|
return false;
|
||||||
|
if (value1.varId == 0 || value2.varId == 0)
|
||||||
|
return true;
|
||||||
|
if (value1.varId == value2.varId && value1.varvalue == value2.varvalue && value1.isIntValue() && value2.isIntValue())
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/** set ValueFlow value and perform calculations if possible */
|
/** set ValueFlow value and perform calculations if possible */
|
||||||
static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Settings *settings)
|
static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Settings *settings)
|
||||||
{
|
{
|
||||||
|
@ -652,9 +665,8 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
|
||||||
continue;
|
continue;
|
||||||
if (value1.isIteratorValue() && value2.isIteratorValue())
|
if (value1.isIteratorValue() && value2.isIteratorValue())
|
||||||
continue;
|
continue;
|
||||||
if (value1.isKnown() || value2.isKnown() || value1.varId == 0 || value2.varId == 0 ||
|
if (!isCompatibleValues(value1, value2))
|
||||||
(value1.varId == value2.varId && value1.varvalue == value2.varvalue && value1.isIntValue() &&
|
continue;
|
||||||
value2.isIntValue())) {
|
|
||||||
ValueFlow::Value result(0);
|
ValueFlow::Value result(0);
|
||||||
combineValueProperties(value1, value2, &result);
|
combineValueProperties(value1, value2, &result);
|
||||||
const double floatValue1 = value1.isIntValue() ? value1.intvalue : value1.floatValue;
|
const double floatValue1 = value1.isIntValue() ? value1.intvalue : value1.floatValue;
|
||||||
|
@ -705,7 +717,6 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// !
|
// !
|
||||||
else if (parent->str() == "!") {
|
else if (parent->str() == "!") {
|
||||||
|
|
|
@ -5629,6 +5629,14 @@ private:
|
||||||
" return x;\n"
|
" return x;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
ASSERT_EQUALS(true, testValueOfXImpossible(code, 3U, -1));
|
ASSERT_EQUALS(true, testValueOfXImpossible(code, 3U, -1));
|
||||||
|
|
||||||
|
code = "size_t g();\n"
|
||||||
|
"auto f(uint16_t j) {\n"
|
||||||
|
" auto x = g() - j;\n"
|
||||||
|
" return x;\n"
|
||||||
|
"}\n";
|
||||||
|
ASSERT_EQUALS(false, testValueOfXImpossible(code, 4U, 0));
|
||||||
|
ASSERT_EQUALS(true, testValueOfXImpossible(code, 4U, -1));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue