From e24134f34a4e298d617fb8eff25062b11565b989 Mon Sep 17 00:00:00 2001 From: James Turner Date: Fri, 10 Aug 2018 15:11:32 +0100 Subject: [PATCH] HID-input: fix crash with null manufacturer name https://sourceforge.net/p/flightgear/codetickets/2041/ --- src/Input/FGHIDEventInput.cxx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Input/FGHIDEventInput.cxx b/src/Input/FGHIDEventInput.cxx index 0e8d088a9..2b1e2bc4a 100644 --- a/src/Input/FGHIDEventInput.cxx +++ b/src/Input/FGHIDEventInput.cxx @@ -315,13 +315,17 @@ FGHIDDevice::FGHIDDevice(hid_device_info *devInfo, FGHIDEventInput *) { _hidPath = devInfo->path; - std::wstring manufactuerName = std::wstring(devInfo->manufacturer_string), + std::wstring manufactuerName, productName = std::wstring(devInfo->product_string); - const auto serial = devInfo->serial_number; - - SetName(simgear::strutils::convertWStringToUtf8(manufactuerName) + " " + + if (devInfo->manufacturer_string) { + manufactuerName = std::wstring(devInfo->manufacturer_string); + SetName(simgear::strutils::convertWStringToUtf8(manufactuerName) + " " + simgear::strutils::convertWStringToUtf8(productName)); + } else { + SetName(simgear::strutils::convertWStringToUtf8(productName)); + } + const auto serial = devInfo->serial_number; // every device so far encountered returns a blank serial number, so we // fall back to the device path to disambiguate. std::string path(devInfo->path);