diff options
author | Abseil Team <absl-team@google.com> | 2022-10-13 14:12:39 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-10-13 14:13:57 -0700 |
commit | f073fe8ee5dcb0aa18c893198747062f2f51ab59 (patch) | |
tree | fa473e3a4a77146484d19b456371452418e4a297 /absl/random | |
parent | cbaba1a9bfdc8900e0d360e87d2fee137f6f7d9e (diff) |
Fix "unsafe narrowing" warnings in absl, 12/12.
Addresses failures with the following, in some files:
-Wshorten-64-to-32
-Wimplicit-int-conversion
-Wsign-compare
-Wsign-conversion
-Wtautological-unsigned-zero-compare
(This specific CL enables these warnings and fixes the remaining known issues.)
Bug: chromium:1292951
PiperOrigin-RevId: 480981210
Change-Id: I92d5023c6833e24d6aa29b10d433116329972f41
Diffstat (limited to 'absl/random')
-rw-r--r-- | absl/random/internal/fast_uniform_bits.h | 3 | ||||
-rw-r--r-- | absl/random/internal/nonsecure_base.h | 2 |
2 files changed, 3 insertions, 2 deletions
diff --git a/absl/random/internal/fast_uniform_bits.h b/absl/random/internal/fast_uniform_bits.h index f3a5c00f..8d8ed045 100644 --- a/absl/random/internal/fast_uniform_bits.h +++ b/absl/random/internal/fast_uniform_bits.h @@ -151,7 +151,8 @@ FastUniformBits<UIntType>::Generate(URBG& g, // NOLINT(runtime/references) result_type r = static_cast<result_type>(g() - kMin); for (size_t n = 1; n < kIters; ++n) { - r = (r << kShift) + static_cast<result_type>(g() - kMin); + r = static_cast<result_type>(r << kShift) + + static_cast<result_type>(g() - kMin); } return r; } diff --git a/absl/random/internal/nonsecure_base.h b/absl/random/internal/nonsecure_base.h index c7d7fa4b..c3b80335 100644 --- a/absl/random/internal/nonsecure_base.h +++ b/absl/random/internal/nonsecure_base.h @@ -44,7 +44,7 @@ class RandenPoolSeedSeq { // Generate random unsigned values directly into the buffer. template <typename Contiguous> void generate_impl(ContiguousTag, Contiguous begin, Contiguous end) { - const size_t n = std::distance(begin, end); + const size_t n = static_cast<size_t>(std::distance(begin, end)); auto* a = &(*begin); RandenPool<uint8_t>::Fill( absl::MakeSpan(reinterpret_cast<uint8_t*>(a), sizeof(*a) * n)); |