From 8a28b95480d25c5fa828a1d0c4954b6523676205 Mon Sep 17 00:00:00 2001 From: Dentomologist Date: Mon, 14 Jul 2025 11:51:45 -0700 Subject: [PATCH] IOFile: Require trivially copyable types Require ReadArray and WriteArray to be called with a trivially copyable type. ReadArray and WriteArray call std::fread and std::fwrite respectively. These functions trigger undefined behavior when the objects are not trivially copyable, so this adds that requirement to the callers. --- Source/Core/Common/IOFile.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Core/Common/IOFile.h b/Source/Core/Common/IOFile.h index 371012060d..2aeff1916b 100644 --- a/Source/Core/Common/IOFile.h +++ b/Source/Core/Common/IOFile.h @@ -54,6 +54,7 @@ public: IOFile Duplicate(const char openmode[]) const; template + requires(std::is_trivially_copyable_v) bool ReadArray(T* elements, size_t count, size_t* num_read = nullptr) { size_t read_count = 0; @@ -67,6 +68,7 @@ public: } template + requires(std::is_trivially_copyable_v) bool WriteArray(const T* elements, size_t count) { if (!IsOpen() || count != std::fwrite(elements, sizeof(T), count, m_file))