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.
This commit is contained in:
Lioncash 2019-05-31 08:36:05 -04:00
parent e0552e0642
commit bcdc5b5f7e

View File

@ -7,6 +7,7 @@
#include <array>
#include <queue>
#include <string>
#include <type_traits>
#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>,
"MessageData must be trivially copyable, as it's copied into emulated memory.");
#pragma pack(pop)
std::queue<MessageData> m_MessageQueue;