Fix 10981: ValueFlow: multiplication with 0 should have known value 0 (#4023)

This commit is contained in:
Paul Fultz II 2022-04-14 11:13:04 -05:00 committed by GitHub
parent 5825ab75db
commit 6deb8068fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 1 deletions

View File

@ -373,7 +373,7 @@ static const Token *getCastTypeStartToken(const Token *parent)
// does the operation cause a loss of information?
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)

View File

@ -876,6 +876,7 @@ private:
ASSERT_EQUALS(0, valueOfTok("(UNKNOWN_TYPE*)0;","(").intvalue);
ASSERT_EQUALS(100, valueOfTok("(int)100.0;", "(").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
ASSERT(tokenValues(";-1<<10;","<<").empty());