Skip to content

Commit

Permalink
pw_random: Make explicit narrowing conversion explicit
Browse files Browse the repository at this point in the history
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 <[email protected]>
Commit-Queue: Ben Lawson <[email protected]>
  • Loading branch information
BenjaminLawson authored and CQ Bot Account committed Dec 21, 2022
1 parent 19b7f07 commit 7e9aa2d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pw_random/public/pw_random/xor_shift.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t>(1) << num_bits) - 1;
uint32_t mask =
static_cast<uint32_t>((static_cast<uint64_t>(1) << num_bits) - 1);
state_ ^= (data & mask);
}

Expand Down

0 comments on commit 7e9aa2d

Please sign in to comment.