From 68b2573a60d145e81cdef7748e4107c84bfa1b47 Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Thu, 28 Nov 2013 23:59:50 +0000 Subject: [PATCH] GPU Calc: Avoid dereferencing null 'score' field in some cases. Change-Id: I2e76d19986326b15c088e6dcce1da3be3924d0fc --- sc/source/core/opencl/opencl_device.cxx | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/sc/source/core/opencl/opencl_device.cxx b/sc/source/core/opencl/opencl_device.cxx index a3fa004b988e..80062c6a9877 100644 --- a/sc/source/core/opencl/opencl_device.cxx +++ b/sc/source/core/opencl/opencl_device.cxx @@ -391,19 +391,26 @@ ds_status pickBestDevice(ds_profile* profile, int* bestDeviceIdx) for (unsigned int d = 0; d < profile->numDevices; d++) { - ds_device device = profile->devices[d]; - LibreOfficeDeviceScore score = *(LibreOfficeDeviceScore*)device.score; + ds_device device = profile->devices[d]; + LibreOfficeDeviceScore *pScore = (LibreOfficeDeviceScore*)device.score; + + float fScore = -1; + if (pScore) + fScore = pScore->fTime; + else + LOG_PRINTF("Unusual null score"); + if (DS_DEVICE_OPENCL_DEVICE == device.type) { - LOG_PRINTF("[DS] Device[" << d << "] " << device.oclDeviceName << " (OpenCL) score is " << score.fTime); + LOG_PRINTF("[DS] Device[" << d << "] " << device.oclDeviceName << " (OpenCL) score is " << fScore); } else { - LOG_PRINTF("[DS] Device[" << d << "] CPU (Native) score is " << score.fTime); + LOG_PRINTF("[DS] Device[" << d << "] CPU (Native) score is " << fScore); } - if (score.fTime < bestScore) + if (fScore < bestScore) { - bestScore = score.fTime; + bestScore = fScore; *bestDeviceIdx = d; } }