ValueFlow: Avoid UB in shift when rhs is negative

This commit is contained in:
Daniel Marjamäki 2020-07-25 14:13:21 +02:00
parent fa8c7ed82c
commit fa32624c93
1 changed files with 9 additions and 7 deletions

View File

@ -2093,12 +2093,10 @@ static bool evalAssignment(ValueFlow::Value &lhsValue, const std::string &assign
else if (assign == "/=") {
if (rhsValue.intvalue == 0)
return false;
else
lhsValue.intvalue /= rhsValue.intvalue;
} else if (assign == "%=") {
if (rhsValue.intvalue == 0)
return false;
else
lhsValue.intvalue %= rhsValue.intvalue;
} else if (assign == "&=")
lhsValue.intvalue &= rhsValue.intvalue;
@ -2106,11 +2104,15 @@ static bool evalAssignment(ValueFlow::Value &lhsValue, const std::string &assign
lhsValue.intvalue |= rhsValue.intvalue;
else if (assign == "^=")
lhsValue.intvalue ^= rhsValue.intvalue;
else if (assign == "<<=")
else if (assign == "<<=") {
if (rhsValue.intvalue < 0)
return false;
lhsValue.intvalue <<= rhsValue.intvalue;
else if (assign == ">>=")
} else if (assign == ">>=") {
if (rhsValue.intvalue < 0)
return false;
lhsValue.intvalue >>= rhsValue.intvalue;
else
} else
return false;
} else if (lhsValue.isFloatValue()) {
if (assign == "=")