From 7e9aa2d94c2bc110226fbdec0528f0d26b303a95 Mon Sep 17 00:00:00 2001 From: Ben Lawson Date: Wed, 21 Dec 2022 02:27:00 +0000 Subject: [PATCH] pw_random: Make explicit narrowing conversion explicit Make implicit conversion of uint64_t to uint32_t in XorShiftStarRng64::InjectEntropyBits explicit. This fixes an error in builds configured with the flags [-Werror,-Wshorten-64-to-32], such as the Fuchsia build. Change-Id: I0e172cb35597b11df2ab4be496815c3556d707b1 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/125050 Reviewed-by: Keir Mierle Commit-Queue: Ben Lawson --- pw_random/public/pw_random/xor_shift.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pw_random/public/pw_random/xor_shift.h b/pw_random/public/pw_random/xor_shift.h index ed1e0a3de9..ad52736d0e 100644 --- a/pw_random/public/pw_random/xor_shift.h +++ b/pw_random/public/pw_random/xor_shift.h @@ -61,7 +61,8 @@ class XorShiftStarRng64 : public RandomGenerator { uint64_t untouched_state = state_ >> (kNumStateBits - num_bits); state_ = untouched_state | (state_ << num_bits); // Zero-out all irrelevant bits, then XOR entropy into state. - uint32_t mask = (static_cast(1) << num_bits) - 1; + uint32_t mask = + static_cast((static_cast(1) << num_bits) - 1); state_ ^= (data & mask); }