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:
Lioncash 2018-07-17 14:53:50 -04:00 committed by Merry
parent e3d533d954
commit 1e303aa1f3

View File

@ -76,8 +76,8 @@ T ArithmeticShiftLeft(T value, int shift_amount) {
return ArithmeticShiftRight(value, -shift_amount);
}
auto signed_value = static_cast<std::make_signed_t<T>>(value);
return static_cast<T>(signed_value << shift_amount);
auto unsigned_value = static_cast<std::make_unsigned_t<T>>(value);
return static_cast<T>(unsigned_value << shift_amount);
}
template<typename T>