Fix 10981: ValueFlow: multiplication with 0 should have known value 0 (#4023)
This commit is contained in:
parent
5825ab75db
commit
6deb8068fa
|
@ -373,7 +373,7 @@ static const Token *getCastTypeStartToken(const Token *parent)
|
||||||
// does the operation cause a loss of information?
|
// does the operation cause a loss of information?
|
||||||
static bool isNonInvertibleOperation(const Token* tok)
|
static bool isNonInvertibleOperation(const Token* tok)
|
||||||
{
|
{
|
||||||
return tok->isComparisonOp() || Token::Match(tok, "%|/|&|%or%|<<|>>|%oror%|&&");
|
return !Token::Match(tok, "+|-");
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isComputableValue(const Token* parent, const ValueFlow::Value& value)
|
static bool isComputableValue(const Token* parent, const ValueFlow::Value& value)
|
||||||
|
|
|
@ -876,6 +876,7 @@ private:
|
||||||
ASSERT_EQUALS(0, valueOfTok("(UNKNOWN_TYPE*)0;","(").intvalue);
|
ASSERT_EQUALS(0, valueOfTok("(UNKNOWN_TYPE*)0;","(").intvalue);
|
||||||
ASSERT_EQUALS(100, valueOfTok("(int)100.0;", "(").intvalue);
|
ASSERT_EQUALS(100, valueOfTok("(int)100.0;", "(").intvalue);
|
||||||
ASSERT_EQUALS(10, valueOfTok("x = static_cast<int>(10);", "( 10 )").intvalue);
|
ASSERT_EQUALS(10, valueOfTok("x = static_cast<int>(10);", "( 10 )").intvalue);
|
||||||
|
ASSERT_EQUALS(0, valueOfTok("x = sizeof (struct {int a;}) * 0;", "*").intvalue);
|
||||||
|
|
||||||
// Don't calculate if there is UB
|
// Don't calculate if there is UB
|
||||||
ASSERT(tokenValues(";-1<<10;","<<").empty());
|
ASSERT(tokenValues(";-1<<10;","<<").empty());
|
||||||
|
|
Loading…
Reference in New Issue