From 314d9cd9b607460f8bfea80fc828b1521ca18443 Mon Sep 17 00:00:00 2001 From: Yaroslav Bulatov Date: Thu, 21 Jul 2016 14:25:35 -0700 Subject: [PATCH] Fix segfault in MacOS when GPU is not available (#3448) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- tensorflow/stream_executor/cuda/cuda_diagnostics.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tensorflow/stream_executor/cuda/cuda_diagnostics.cc b/tensorflow/stream_executor/cuda/cuda_diagnostics.cc index a2fd85e7bc2..54e00d5a747 100644 --- a/tensorflow/stream_executor/cuda/cuda_diagnostics.cc +++ b/tensorflow/stream_executor/cuda/cuda_diagnostics.cc @@ -314,8 +314,17 @@ port::StatusOr 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);