summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2020-01-14 15:09:10 +0100
committerEike Ziller <eike.ziller@qt.io>2020-01-15 08:20:10 +0000
commit82d830e5d80aa0dce5538dd3f87d69e7a1269de0 (patch)
tree14eae0cd202b3db4f6a89d490f2b1a2b9cdd4791
parent833d278dcee03016aa559fb61fb944f3f6b2d088 (diff)
downloadqt-creator-82d830e5d80aa0dce5538dd3f87d69e7a1269de0.tar.gz
iOS: Guard against failure to retrieve device UID
It should not happen, but if it happens, Qt Creator should not crash. Task-number: QTCREATORBUG-23460 Change-Id: Id25b53ff24d7e1726efc344dc6318c32073ee75c Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
-rw-r--r--src/plugins/ios/iosdevice.cpp33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/plugins/ios/iosdevice.cpp b/src/plugins/ios/iosdevice.cpp
index e3438ffb71..e341c62516 100644
--- a/src/plugins/ios/iosdevice.cpp
+++ b/src/plugins/ios/iosdevice.cpp
@@ -356,9 +356,14 @@ void deviceConnectedCallback(void *refCon, io_iterator_t iterator)
usbDevice,
CFSTR(kUSBSerialNumberString),
kCFAllocatorDefault, 0));
- QString uid = CFStringRef2QString(cfUid);
- CFRelease(cfUid);
- IosDeviceManager::instance()->deviceConnected(uid, name);
+ if (cfUid) {
+ QString uid = CFStringRef2QString(cfUid);
+ CFRelease(cfUid);
+ qCDebug(detectLog) << "device UID is" << uid;
+ IosDeviceManager::instance()->deviceConnected(uid, name);
+ } else {
+ qCDebug(detectLog) << "failed to retrieve device's UID";
+ }
// Done with this USB device; release the reference added by IOIteratorNext
kr = IOObjectRelease(usbDevice);
@@ -385,18 +390,22 @@ void deviceDisconnectedCallback(void *refCon, io_iterator_t iterator)
// Get the USB device's name.
kr = IORegistryEntryGetName(usbDevice, deviceName);
- if (KERN_SUCCESS != kr)
- deviceName[0] = '\0';
- qCDebug(detectLog) << "ios device " << deviceName << " in deviceDisconnectedCallback";
-
- {
- CFStringRef cfUid = static_cast<CFStringRef>(IORegistryEntryCreateCFProperty(
- usbDevice,
- CFSTR(kUSBSerialNumberString),
- kCFAllocatorDefault, 0));
+ QString name;
+ if (KERN_SUCCESS == kr)
+ name = QString::fromLocal8Bit(deviceName);
+ qCDebug(detectLog) << "ios device " << name << " in deviceDisconnectedCallback";
+
+ CFStringRef cfUid = static_cast<CFStringRef>(
+ IORegistryEntryCreateCFProperty(usbDevice,
+ CFSTR(kUSBSerialNumberString),
+ kCFAllocatorDefault,
+ 0));
+ if (cfUid) {
QString uid = CFStringRef2QString(cfUid);
CFRelease(cfUid);
IosDeviceManager::instance()->deviceDisconnected(uid);
+ } else {
+ qCDebug(detectLog) << "failed to retrieve device's UID";
}
// Done with this USB device; release the reference added by IOIteratorNext