| Index: webrtc/base/random_unittest.cc
|
| diff --git a/webrtc/base/random_unittest.cc b/webrtc/base/random_unittest.cc
|
| index 3b47a00806eb0fc29ae0e43568df0f8b19fde960..ae1a0a2f5122004399404afa7ea316f7c8a52c8c 100644
|
| --- a/webrtc/base/random_unittest.cc
|
| +++ b/webrtc/base/random_unittest.cc
|
| @@ -14,6 +14,7 @@
|
| #include <vector>
|
|
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| +#include "webrtc/base/mathutils.h" // unsigned difference
|
| #include "webrtc/base/random.h"
|
|
|
| namespace webrtc {
|
| @@ -118,7 +119,7 @@ void BucketTestSignedInterval(unsigned int bucket_count,
|
|
|
| ASSERT_GE(high, low);
|
| ASSERT_GE(bucket_count, 2u);
|
| - uint32_t interval = static_cast<uint32_t>(high - low + 1);
|
| + uint32_t interval = unsigned_difference<int32_t>(high, low) + 1;
|
| uint32_t numbers_per_bucket;
|
| if (interval == 0) {
|
| // The computation high - low + 1 should be 2^32 but overflowed
|
| @@ -134,7 +135,7 @@ void BucketTestSignedInterval(unsigned int bucket_count,
|
| int32_t sample = prng->Rand(low, high);
|
| EXPECT_LE(low, sample);
|
| EXPECT_GE(high, sample);
|
| - buckets[static_cast<uint32_t>(sample - low) / numbers_per_bucket]++;
|
| + buckets[unsigned_difference<int32_t>(sample, low) / numbers_per_bucket]++;
|
| }
|
|
|
| for (unsigned int i = 0; i < bucket_count; i++) {
|
| @@ -158,7 +159,7 @@ void BucketTestUnsignedInterval(unsigned int bucket_count,
|
|
|
| ASSERT_GE(high, low);
|
| ASSERT_GE(bucket_count, 2u);
|
| - uint32_t interval = static_cast<uint32_t>(high - low + 1);
|
| + uint32_t interval = high - low + 1;
|
| uint32_t numbers_per_bucket;
|
| if (interval == 0) {
|
| // The computation high - low + 1 should be 2^32 but overflowed
|
| @@ -174,7 +175,7 @@ void BucketTestUnsignedInterval(unsigned int bucket_count,
|
| uint32_t sample = prng->Rand(low, high);
|
| EXPECT_LE(low, sample);
|
| EXPECT_GE(high, sample);
|
| - buckets[static_cast<uint32_t>(sample - low) / numbers_per_bucket]++;
|
| + buckets[(sample - low) / numbers_per_bucket]++;
|
| }
|
|
|
| for (unsigned int i = 0; i < bucket_count; i++) {
|
|
|