Fix segfault in MacOS when GPU is not available (#3448)

* Fix sigsegv in MacOS when GPU is not available

* Change info link to point to Apple docs

* Invert NULL checking logic

* fix indentation

* Re-align to get change to fit in 80 chars

* Run clang-format —style=google on changes
This commit is contained in:
Yaroslav Bulatov 2016-07-21 14:25:35 -07:00 committed by Vijay Vasudevan
parent 196bdf8e87
commit 314d9cd9b6

View File

@ -314,8 +314,17 @@ port::StatusOr<DriverVersion> Diagnostician::FindKernelDriverVersion() {
if (CFDictionaryGetValueIfPresent(kext_infos, kDriverKextIdentifier, (const void**)&cuda_driver_info)) {
// NOTE: OSX CUDA driver does not currently store the same driver version
// in kCFBundleVersionKey as is returned by cuDriverGetVersion
const char * version = CFStringGetCStringPtr((CFStringRef)CFDictionaryGetValue(cuda_driver_info, kCFBundleVersionKey), kCFStringEncodingUTF8);
CFRelease(kext_infos);
const CFStringRef str = (CFStringRef)CFDictionaryGetValue(
cuda_driver_info, kCFBundleVersionKey);
const char *version = CFStringGetCStringPtr(str, kCFStringEncodingUTF8);
// version can be NULL in which case treat it as empty string
// see
// https://developer.apple.com/library/mac/documentation/CoreFoundation/Conceptual/CFStrings/Articles/AccessingContents.html#//apple_ref/doc/uid/20001184-100980-TPXREF112
if (version == NULL) {
return StringToDriverVersion("");
}
return StringToDriverVersion(version);
}
CFRelease(kext_infos);