From 8b693ed7bbd962c4b0ea3aaaa3b44d916e25a196 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Sun, 22 Jul 2018 11:52:56 +0200 Subject: [PATCH] MMJOYSTICK: fix nullpointer crash in GetMMJOYDevice --- rpcs3/ds4_pad_handler.cpp | 2 +- rpcs3/mm_joystick_handler.cpp | 19 ++++++++++++------- rpcs3/mm_joystick_handler.h | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/rpcs3/ds4_pad_handler.cpp b/rpcs3/ds4_pad_handler.cpp index ca517cd53c..36403647cf 100644 --- a/rpcs3/ds4_pad_handler.cpp +++ b/rpcs3/ds4_pad_handler.cpp @@ -753,7 +753,7 @@ bool ds4_pad_handler::Init() } if (controllers.size() == 0) - LOG_ERROR(HLE, "[DS4] No controllers found!"); + LOG_WARNING(HLE, "[DS4] No controllers found!"); else LOG_SUCCESS(HLE, "[DS4] Controllers found: %d", controllers.size()); diff --git a/rpcs3/mm_joystick_handler.cpp b/rpcs3/mm_joystick_handler.cpp index 5a6cbeff4b..73aa21ac50 100644 --- a/rpcs3/mm_joystick_handler.cpp +++ b/rpcs3/mm_joystick_handler.cpp @@ -91,7 +91,7 @@ bool mm_joystick_handler::Init() { MMJOYDevice dev; - if (GetMMJOYDevice(i, dev) == false) + if (GetMMJOYDevice(i, &dev) == false) continue; m_devices.emplace(i, dev); @@ -226,7 +226,7 @@ void mm_joystick_handler::ThreadProc() if (last_connection_status[i] == false) { - if (GetMMJOYDevice(m_dev->device_id, *m_dev) == false) + if (GetMMJOYDevice(m_dev->device_id, m_dev.get()) == false) continue; LOG_SUCCESS(HLE, "MMJOY Device %d reconnected.", m_dev->device_id); pad->m_port_status |= CELL_PAD_STATUS_CONNECTED; @@ -558,8 +558,13 @@ int mm_joystick_handler::GetIDByName(const std::string& name) return -1; } -bool mm_joystick_handler::GetMMJOYDevice(int index, MMJOYDevice& dev) +bool mm_joystick_handler::GetMMJOYDevice(int index, MMJOYDevice* dev) { + if (!dev) + { + return false; + } + JOYINFOEX js_info; JOYCAPS js_caps; js_info.dwSize = sizeof(js_info); @@ -574,10 +579,10 @@ bool mm_joystick_handler::GetMMJOYDevice(int index, MMJOYDevice& dev) LOG_NOTICE(GENERAL, "Joystick nr.%d found. Driver: %s", index, drv); - dev.device_id = index; - dev.device_name = m_name_string + std::to_string(index); - dev.device_info = js_info; - dev.device_caps = js_caps; + dev->device_id = index; + dev->device_name = m_name_string + std::to_string(index); + dev->device_info = js_info; + dev->device_caps = js_caps; return true; } diff --git a/rpcs3/mm_joystick_handler.h b/rpcs3/mm_joystick_handler.h index 08f1881dba..e8de2afba0 100644 --- a/rpcs3/mm_joystick_handler.h +++ b/rpcs3/mm_joystick_handler.h @@ -115,7 +115,7 @@ private: void TranslateButtonPress(u64 keyCode, bool& pressed, u16& val, bool ignore_threshold = false) override; std::unordered_map GetButtonValues(const JOYINFOEX& js_info, const JOYCAPS& js_caps); int GetIDByName(const std::string& name); - bool GetMMJOYDevice(int index, MMJOYDevice& dev); + bool GetMMJOYDevice(int index, MMJOYDevice* dev); bool is_init = false; u32 m_supported_joysticks = 0;