diff --git a/app/src/main/cpp/skyline/common.h b/app/src/main/cpp/skyline/common.h index 359de46c..7b3dab13 100644 --- a/app/src/main/cpp/skyline/common.h +++ b/app/src/main/cpp/skyline/common.h @@ -340,6 +340,20 @@ namespace skyline { return frz::elsa{}(frz::string(view.data(), view.size()), 0); } + /** + * @brief Selects the largest possible integer type for representing an object alongside providing the size of the object in terms of the underlying type + */ + template + struct IntegerFor { + using type = std::conditional_t + > + >; + + static constexpr size_t count{sizeof(T) / sizeof(type)}; + }; + namespace detail { static thread_local std::mt19937_64 generator{GetTimeTicks()}; } @@ -354,6 +368,11 @@ namespace skyline { std::generate(in.begin(), in.end(), gen); } + + template requires (!std::is_integral_v && std::is_trivially_copyable_v) + void FillRandomBytes(T &object) { + FillRandomBytes(std::span(reinterpret_cast::type *>(&object), IntegerFor::count)); + } } /** diff --git a/app/src/main/cpp/skyline/common/uuid.cpp b/app/src/main/cpp/skyline/common/uuid.cpp index a5ce4e81..9ea9baf9 100644 --- a/app/src/main/cpp/skyline/common/uuid.cpp +++ b/app/src/main/cpp/skyline/common/uuid.cpp @@ -58,7 +58,7 @@ namespace skyline { // Create an initial random UUID UuidLayout uuid; - util::FillRandomBytes(span(&uuid, 1).cast()); + util::FillRandomBytes(uuid); // Set format bits uuid.reserved = reserved;