Commit 0397125f authored by eroman's avatar eroman Committed by Commit bot

Fix a division by zero when multiplying 0 * y with SafeNumerics.

BUG=488302

Review URL: https://codereview.chromium.org/1142783002

Cr-Commit-Position: refs/heads/master@{#330357}
parent a19f1247
......@@ -176,8 +176,8 @@ typename enable_if<std::numeric_limits<T>::is_integer&& std::numeric_limits<
T>::is_signed&&(sizeof(T) * 2 > sizeof(uintmax_t)),
T>::type
CheckedMul(T x, T y, RangeConstraint* validity) {
// if either side is zero then the result will be zero.
if (!(x || y)) {
// If either side is zero then the result will be zero.
if (!x || !y) {
return RANGE_VALID;
} else if (x > 0) {
......
......@@ -239,6 +239,9 @@ static void TestArithmetic(const char* dst, int line) {
TEST_EXPECTED_VALUE(0, (CheckedNumeric<Dst>() * 1));
TEST_EXPECTED_VALUE(1, (CheckedNumeric<Dst>(1) * 1));
TEST_EXPECTED_VALUE(-2, (CheckedNumeric<Dst>(-1) * 2));
TEST_EXPECTED_VALUE(0, (CheckedNumeric<Dst>(0) * 0));
TEST_EXPECTED_VALUE(0, (CheckedNumeric<Dst>(-1) * 0));
TEST_EXPECTED_VALUE(0, (CheckedNumeric<Dst>(0) * -1));
TEST_EXPECTED_VALIDITY(
RANGE_OVERFLOW, CheckedNumeric<Dst>(DstLimits::max()) * DstLimits::max());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment