Permalink
Browse files

WiimoteDevice: Get rid of pointer casting in CBigEndianBuffer

Gets rid of more places where we can violate alignment requirements and
aliasing rules.
  • Loading branch information...
lioncash committed Jun 2, 2018
1 parent 13e828f commit 4601136b0876c26105bfc45153128a8dc5065efd
Showing with 12 additions and 4 deletions.
  1. +12 −4 Source/Core/Core/IOS/USB/Bluetooth/WiimoteDevice.cpp
@@ -32,11 +32,19 @@ class CBigEndianBuffer
public:
CBigEndianBuffer(u8* pBuffer) : m_pBuffer(pBuffer) {}
u8 Read8(u32 offset) const { return m_pBuffer[offset]; }
u16 Read16(u32 offset) const { return Common::swap16(*(u16*)&m_pBuffer[offset]); }
u32 Read32(u32 offset) const { return Common::swap32(*(u32*)&m_pBuffer[offset]); }
u16 Read16(u32 offset) const { return Common::swap16(&m_pBuffer[offset]); }
u32 Read32(u32 offset) const { return Common::swap32(&m_pBuffer[offset]); }
void Write8(u32 offset, u8 data) { m_pBuffer[offset] = data; }
void Write16(u32 offset, u16 data) { *(u16*)&m_pBuffer[offset] = Common::swap16(data); }
void Write32(u32 offset, u32 data) { *(u32*)&m_pBuffer[offset] = Common::swap32(data); }
void Write16(u32 offset, u16 data)
{
const u16 swapped = Common::swap16(data);
std::memcpy(&m_pBuffer[offset], &swapped, sizeof(u16));
}
void Write32(u32 offset, u32 data)
{
const u32 swapped = Common::swap32(data);
std::memcpy(&m_pBuffer[offset], &swapped, sizeof(u32));
}
u8* GetPointer(u32 offset) { return &m_pBuffer[offset]; }
private:

0 comments on commit 4601136

Please sign in to comment.