diff --git a/rand/rdrand.cpp b/rand/rdrand.cpp index 6bcb1b0d..3d08ff65 100644 --- a/rand/rdrand.cpp +++ b/rand/rdrand.cpp @@ -40,5 +40,9 @@ rdrand::operator() () if (!__builtin_expect(success, 1)) throw std::runtime_error ("no value available for rdrand"); - return res; + // As long as the u64 we just grabbed is of a type we can truncate then + // we'll do just that and return it. + static_assert (sizeof (result_type) <= sizeof (res)); + static_assert (std::is_signed_v == std::is_signed_v); + return static_cast (res); }