NintendoPowerA: Use std::memcpy within transferCycle()

Eliminates undefined behavior within the function.
This commit is contained in:
Lioncash 2019-09-06 07:30:10 -04:00
parent 4b82c6510f
commit f445df1701
1 changed files with 3 additions and 2 deletions

View File

@ -27,7 +27,8 @@ void NintendoPowerA::transferCycle() {
return;
}
NintendoPowerAState state = *reinterpret_cast<NintendoPowerAState*>(&payload);
NintendoPowerAState state;
std::memcpy(&state, payload.data(), sizeof(state));
std::lock_guard lk{m_callbackLock};
if (state != m_last && m_callback != nullptr) {
@ -41,7 +42,7 @@ void NintendoPowerA::finalCycle() {}
void NintendoPowerA::receivedHIDReport(const uint8_t* data, size_t length, HIDReportType tp, uint32_t message) {}
bool NintendoPowerAState::operator==(const NintendoPowerAState& other) const {
return memcmp(this, &other, sizeof(NintendoPowerAState)) == 0;
return std::memcmp(this, &other, sizeof(NintendoPowerAState)) == 0;
}
bool NintendoPowerAState::operator!=(const NintendoPowerAState& other) const { return !operator==(other); }