ValueFlow: Avoid UB in shift when rhs is negative
This commit is contained in:
parent
fa8c7ed82c
commit
fa32624c93
|
@ -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 == "=")
|
||||
|
|
Loading…
Reference in New Issue