Chromium Code Reviews| Index: base/rand_util.cc |
| diff --git a/base/rand_util.cc b/base/rand_util.cc |
| index 931eb4e943e646e2f39e2848b33683247b5b4725..655ff5bbde6fb51aba66472bab55e78bf04dd20a 100644 |
| --- a/base/rand_util.cc |
| +++ b/base/rand_util.cc |
| @@ -20,7 +20,10 @@ int RandInt(int min, int max) { |
| DCHECK_LE(min, max); |
| uint64 range = static_cast<uint64>(max) - min + 1; |
| - int result = min + static_cast<int>(base::RandGenerator(range)); |
| + // |range| is at most UINT_MAX + 1, so the result of RandGenerator(range) |
| + // is at most UINT_MAX. Hence it's safe to cast it from uint64 to int64. |
| + int result = |
| + static_cast<int>(min + static_cast<int64>(base::RandGenerator(range))); |
|
Lei Zhang
2015/10/29 16:38:15
int64_t, and fix line 22 as well?
Nico
2015/10/29 16:46:45
Done.
|
| DCHECK_GE(result, min); |
| DCHECK_LE(result, max); |
| return result; |