From bcdc5b5f7e94ebee49ccc8de77cc54cb9d64b372 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 31 May 2019 08:36:05 -0400 Subject: [PATCH] IOS/USB_KBD: Add static assertion to enforce MessageData as trivially copyable MessageData must be a trivially copyable type, given it's copied into emulated memory via our memory copy function CopyToEmu. Under the covers, this function utilizes memcpy. One of memcpy's requirements is that pointers to it point to types that are trivially copyable, otherwise the behavior is undefined. Given that, we can enforce this requirement at compile-time. --- Source/Core/Core/IOS/USB/USB_KBD.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/Core/Core/IOS/USB/USB_KBD.h b/Source/Core/Core/IOS/USB/USB_KBD.h index bd53e0ae0e..d0039d4ba7 100644 --- a/Source/Core/Core/IOS/USB/USB_KBD.h +++ b/Source/Core/Core/IOS/USB/USB_KBD.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "Common/CommonTypes.h" #include "Core/IOS/Device.h" @@ -45,6 +46,8 @@ private: MessageData(u32 msg_type, u8 modifiers, PressedKeyData pressed_keys); }; + static_assert(std::is_trivially_copyable_v, + "MessageData must be trivially copyable, as it's copied into emulated memory."); #pragma pack(pop) std::queue m_MessageQueue;