WiimoteDevice: Get rid of pointer casting in CBigEndianBuffer

Gets rid of more places where we can violate alignment requirements and
aliasing rules.
This commit is contained in:
Lioncash 2018-06-02 14:57:16 -04:00
parent 13e828fd4d
commit 4601136b08
1 changed files with 12 additions and 4 deletions

View File

@ -32,11 +32,19 @@ class CBigEndianBuffer
public: public:
CBigEndianBuffer(u8* pBuffer) : m_pBuffer(pBuffer) {} CBigEndianBuffer(u8* pBuffer) : m_pBuffer(pBuffer) {}
u8 Read8(u32 offset) const { return m_pBuffer[offset]; } u8 Read8(u32 offset) const { return m_pBuffer[offset]; }
u16 Read16(u32 offset) const { return Common::swap16(*(u16*)&m_pBuffer[offset]); } u16 Read16(u32 offset) const { return Common::swap16(&m_pBuffer[offset]); }
u32 Read32(u32 offset) const { return Common::swap32(*(u32*)&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 Write8(u32 offset, u8 data) { m_pBuffer[offset] = data; }
void Write16(u32 offset, u16 data) { *(u16*)&m_pBuffer[offset] = Common::swap16(data); } void Write16(u32 offset, u16 data)
void Write32(u32 offset, u32 data) { *(u32*)&m_pBuffer[offset] = Common::swap32(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]; } u8* GetPointer(u32 offset) { return &m_pBuffer[offset]; }
private: private: