From a7a4fa4b628526a5d9138ed56bb195be71bac118 Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Fri, 26 Jun 2015 11:30:19 +0300 Subject: Fix crash in QSPI::availablePorts() on OS X 10.10 CFTypeRef returned by IORegistryEntrySearchCFProperty sometimes may be of unexpected type (as CFStringRef instead of CFNumberRef). In this case the CFNumberGetValue() throws the exception. The simplest fix is to check the type in searchShortIntProperty() before calling CFNumberGetValue(): CFGetTypeID(result.as()) == CFNumberGetTypeID(). Thanks to Orest Hera. Task-number: QTBUG-46875 Change-Id: Id86993c008595f9762a08739bf4c5f5662643e92 Reviewed-by: Dyami Caliri Reviewed-by: Jake Petroules --- src/serialport/qserialportinfo_mac.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/serialport/qserialportinfo_mac.cpp b/src/serialport/qserialportinfo_mac.cpp index 558dcbd..8d4034a 100644 --- a/src/serialport/qserialportinfo_mac.cpp +++ b/src/serialport/qserialportinfo_mac.cpp @@ -72,9 +72,10 @@ static quint16 searchShortIntProperty(io_registry_entry_t ioRegistryEntry, bool &ok) { const QCFType result(searchProperty(ioRegistryEntry, propertyKey)); + const CFNumberRef ref = result.as(); quint16 value = 0; - ok = result.as() - && (::CFNumberGetValue(result.as(), kCFNumberShortType, &value) > 0); + ok = ref && (::CFGetTypeID(ref) == ::CFNumberGetTypeID()) + && (::CFNumberGetValue(ref, kCFNumberShortType, &value) > 0); return value; } -- cgit v1.2.1