mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 21:30:19 -06:00
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.
This commit is contained in:
@ -54,6 +54,7 @@ public:
|
||||
IOFile Duplicate(const char openmode[]) const;
|
||||
|
||||
template <typename T>
|
||||
requires(std::is_trivially_copyable_v<T>)
|
||||
bool ReadArray(T* elements, size_t count, size_t* num_read = nullptr)
|
||||
{
|
||||
size_t read_count = 0;
|
||||
@ -67,6 +68,7 @@ public:
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
requires(std::is_trivially_copyable_v<T>)
|
||||
bool WriteArray(const T* elements, size_t count)
|
||||
{
|
||||
if (!IsOpen() || count != std::fwrite(elements, sizeof(T), count, m_file))
|
||||
|
Reference in New Issue
Block a user