Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Fix a division by zero when multiplying 0 * y with SafeNumerics.
Browse files Browse the repository at this point in the history
BUG=488302

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

Cr-Commit-Position: refs/heads/master@{#330357}
  • Loading branch information
eroman authored and Commit bot committed May 18, 2015
1 parent a19f124 commit 0397125
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/numerics/safe_math_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions base/numerics/safe_numerics_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down

0 comments on commit 0397125

Please sign in to comment.