From 15e9fa1c80b8ff882ebf49bc48d0b115187b4f7b Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Tue, 10 May 2022 18:28:15 +0100 Subject: [PATCH] Fix FillRandomBytes There were two issues here: - If a skyline span was passed as a param then the 'T &object' version would be called, filling the span itself with random values rather than its contents - Random numbers were repeated every call since independent_bits_engine copied generator state and thus it was never actually updated --- app/src/main/cpp/skyline/common/utils.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/cpp/skyline/common/utils.h b/app/src/main/cpp/skyline/common/utils.h index f8c6b390..1ced47a3 100644 --- a/app/src/main/cpp/skyline/common/utils.h +++ b/app/src/main/cpp/skyline/common/utils.h @@ -237,12 +237,12 @@ namespace skyline::util { template requires std::is_integral_v void FillRandomBytes(std::span in) { - std::independent_bits_engine::digits, T> gen(detail::generator); - std::generate(in.begin(), in.end(), gen); + std::uniform_int_distribution dist(std::numeric_limits::min(), std::numeric_limits::max()); + std::generate(in.begin(), in.end(), [&]() { return dist(detail::generator); }); } template - requires (!std::is_integral_v && std::is_trivially_copyable_v) + requires (std::is_trivially_copyable_v && !requires (T v) { v.data(); }) void FillRandomBytes(T &object) { FillRandomBytes(std::span(reinterpret_cast::Type *>(&object), IntegerFor::Count)); }