From 3026feeebed54ad430f3d29fe279edba9fed222c Mon Sep 17 00:00:00 2001 From: Martin Hartl Date: Fri, 5 Feb 2021 15:55:35 +0100 Subject: [PATCH] DS4: Check return value of get serial call --- Controllers/SonyDS4Controller/SonyDS4Controller.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Controllers/SonyDS4Controller/SonyDS4Controller.cpp b/Controllers/SonyDS4Controller/SonyDS4Controller.cpp index 7f67b123..af1c7f6d 100644 --- a/Controllers/SonyDS4Controller/SonyDS4Controller.cpp +++ b/Controllers/SonyDS4Controller/SonyDS4Controller.cpp @@ -27,7 +27,7 @@ SonyDS4Controller::SonyDS4Controller(hid_device * device_handle, const char * de break; } } - + location = device_path; } @@ -44,7 +44,11 @@ std::string SonyDS4Controller::GetLocation() std::string SonyDS4Controller::GetSerialString() { wchar_t serial_string[128]; - hid_get_serial_number_string(device_handle, serial_string, 128); + int ret = hid_get_serial_number_string(device_handle, serial_string, 128); + if(ret != 0) + { + return(""); + } std::wstring return_wstring = serial_string; std::string return_string(return_wstring.begin(), return_wstring.end()); @@ -74,7 +78,7 @@ void SonyDS4Controller::sendReportBT(unsigned char red, unsigned char green, uns 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - + uint32_t crc = CRCPP::CRC::Calculate(buffer, 75, CRCPP::CRC::CRC_32()); unsigned char outbuffer[78]; @@ -95,7 +99,7 @@ void SonyDS4Controller::sendReportBT(unsigned char red, unsigned char green, uns outbuffer[75] = (0x0000FF00 & crc) >> 8; outbuffer[76] = (0x00FF0000 & crc) >> 16; outbuffer[77] = (0xFF000000 & crc) >> 24; - + hid_write(device_handle, outbuffer, 78); }