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 == "/=") {
|
else if (assign == "/=") {
|
||||||
if (rhsValue.intvalue == 0)
|
if (rhsValue.intvalue == 0)
|
||||||
return false;
|
return false;
|
||||||
else
|
|
||||||
lhsValue.intvalue /= rhsValue.intvalue;
|
lhsValue.intvalue /= rhsValue.intvalue;
|
||||||
} else if (assign == "%=") {
|
} else if (assign == "%=") {
|
||||||
if (rhsValue.intvalue == 0)
|
if (rhsValue.intvalue == 0)
|
||||||
return false;
|
return false;
|
||||||
else
|
|
||||||
lhsValue.intvalue %= rhsValue.intvalue;
|
lhsValue.intvalue %= rhsValue.intvalue;
|
||||||
} else if (assign == "&=")
|
} else if (assign == "&=")
|
||||||
lhsValue.intvalue &= rhsValue.intvalue;
|
lhsValue.intvalue &= rhsValue.intvalue;
|
||||||
|
@ -2106,11 +2104,15 @@ static bool evalAssignment(ValueFlow::Value &lhsValue, const std::string &assign
|
||||||
lhsValue.intvalue |= rhsValue.intvalue;
|
lhsValue.intvalue |= rhsValue.intvalue;
|
||||||
else if (assign == "^=")
|
else if (assign == "^=")
|
||||||
lhsValue.intvalue ^= rhsValue.intvalue;
|
lhsValue.intvalue ^= rhsValue.intvalue;
|
||||||
else if (assign == "<<=")
|
else if (assign == "<<=") {
|
||||||
|
if (rhsValue.intvalue < 0)
|
||||||
|
return false;
|
||||||
lhsValue.intvalue <<= rhsValue.intvalue;
|
lhsValue.intvalue <<= rhsValue.intvalue;
|
||||||
else if (assign == ">>=")
|
} else if (assign == ">>=") {
|
||||||
|
if (rhsValue.intvalue < 0)
|
||||||
|
return false;
|
||||||
lhsValue.intvalue >>= rhsValue.intvalue;
|
lhsValue.intvalue >>= rhsValue.intvalue;
|
||||||
else
|
} else
|
||||||
return false;
|
return false;
|
||||||
} else if (lhsValue.isFloatValue()) {
|
} else if (lhsValue.isFloatValue()) {
|
||||||
if (assign == "=")
|
if (assign == "=")
|
||||||
|
|
Loading…
Reference in New Issue