safe_ops: Avoid cases where shift bases are invalid with signed values
For example, say the converted signed type is s64, shifting left by 63 bits would be undefined behavior. However, given an ASL is essentially the same behavior as an LSL we can just use an unsigned type instead of converting to a signed type.
This commit is contained in:
parent
d0274f412a
commit
84affdb260
1 changed files with 2 additions and 2 deletions
|
@ -76,8 +76,8 @@ T ArithmeticShiftLeft(T value, int shift_amount) {
|
||||||
return ArithmeticShiftRight(value, -shift_amount);
|
return ArithmeticShiftRight(value, -shift_amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto signed_value = static_cast<std::make_signed_t<T>>(value);
|
auto unsigned_value = static_cast<std::make_unsigned_t<T>>(value);
|
||||||
return static_cast<T>(signed_value << shift_amount);
|
return static_cast<T>(unsigned_value << shift_amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
Loading…
Reference in a new issue