From f445df17018f1e462d30056b3b25e024c5706682 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 6 Sep 2019 07:30:10 -0400 Subject: [PATCH] NintendoPowerA: Use std::memcpy within transferCycle() Eliminates undefined behavior within the function. --- lib/inputdev/NintendoPowerA.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/inputdev/NintendoPowerA.cpp b/lib/inputdev/NintendoPowerA.cpp index 2da33d2..788cacd 100644 --- a/lib/inputdev/NintendoPowerA.cpp +++ b/lib/inputdev/NintendoPowerA.cpp @@ -27,7 +27,8 @@ void NintendoPowerA::transferCycle() { return; } - NintendoPowerAState state = *reinterpret_cast(&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); }