This patch fix some bugs found by unit tests like passing a wrong device type all the devices(gpu, cpu and accelarator) was being created, ignore paramValue if it is NULL and return invalid_value if paramValueSize != paramValueSizeReturn .
ps: the patch is in annex too. diff --git a/src/api/api_device.cpp b/src/api/api_device.cpp index f91ad29..4d6bf19 100644 --- a/src/api/api_device.cpp +++ b/src/api/api_device.cpp @@ -73,13 +73,13 @@ clGetDeviceIDs(cl_device_type device_type, gpu = (device_type & CL_DEVICE_TYPE_DEFAULT) || (device_type & CL_DEVICE_TYPE_GPU) || - (device_type & CL_DEVICE_TYPE_ALL); + !(device_type ^ CL_DEVICE_TYPE_ALL); cpu = (device_type & CL_DEVICE_TYPE_CPU) || - (device_type & CL_DEVICE_TYPE_ALL); + !(device_type ^ CL_DEVICE_TYPE_ALL); accelerator = (device_type & CL_DEVICE_TYPE_ACCELERATOR) || - (device_type & CL_DEVICE_TYPE_ALL); + !(device_type ^ CL_DEVICE_TYPE_ALL); if (!gpu && !cpu && !accelerator) return CL_INVALID_DEVICE_TYPE; diff --git a/src/core/device.cpp b/src/core/device.cpp index c300f79..20e6f2b 100644 --- a/src/core/device.cpp +++ b/src/core/device.cpp @@ -39,9 +39,12 @@ Device * Device::create(cl_uint type) static void stringToParam(const std::string &str, void * paramValue, + size_t paramValueSize, size_t * paramValueSizeRet) { - strcpy((char*)paramValue, str.c_str()); + char *paramCharValue = (char *)paramValue; + paramCharValue[paramValueSize - 1] = 0; + strncpy(paramCharValue, str.c_str(), paramValueSize - 1); if (paramValueSizeRet) *paramValueSizeRet = str.size(); } @@ -51,8 +54,14 @@ cl_int Device::info(cl_device_info opcode, void * paramValue, size_t * paramValueSizeRet) const { + if (!paramValue) + return CL_SUCCESS; + switch (opcode) { case CL_DEVICE_TYPE: + if (paramValueSizeRet) + *paramValueSizeRet = sizeof(type()); + ((cl_int*)paramValue)[0] = type(); break; case CL_DEVICE_VENDOR_ID: @@ -140,10 +149,10 @@ cl_int Device::info(cl_device_info opcode, case CL_DEVICE_QUEUE_PROPERTIES: break; case CL_DEVICE_NAME: - stringToParam(m_info.name, paramValue, paramValueSizeRet); + stringToParam(m_info.name, paramValue, paramValueSize, paramValueSizeRet); break; case CL_DEVICE_VENDOR: - stringToParam(m_info.name, paramValue, paramValueSizeRet); + stringToParam(m_info.name, paramValue, paramValueSize, paramValueSizeRet); break; case CL_DRIVER_VERSION: break; @@ -159,6 +168,9 @@ cl_int Device::info(cl_device_info opcode, break; } + if (paramValueSizeRet && paramValueSize != *paramValueSizeRet) + return CL_INVALID_VALUE; + return CL_SUCCESS; }
diff --git a/src/api/api_device.cpp b/src/api/api_device.cpp index f91ad29..4d6bf19 100644 --- a/src/api/api_device.cpp +++ b/src/api/api_device.cpp @@ -73,13 +73,13 @@ clGetDeviceIDs(cl_device_type device_type, gpu = (device_type & CL_DEVICE_TYPE_DEFAULT) || (device_type & CL_DEVICE_TYPE_GPU) || - (device_type & CL_DEVICE_TYPE_ALL); + !(device_type ^ CL_DEVICE_TYPE_ALL); cpu = (device_type & CL_DEVICE_TYPE_CPU) || - (device_type & CL_DEVICE_TYPE_ALL); + !(device_type ^ CL_DEVICE_TYPE_ALL); accelerator = (device_type & CL_DEVICE_TYPE_ACCELERATOR) || - (device_type & CL_DEVICE_TYPE_ALL); + !(device_type ^ CL_DEVICE_TYPE_ALL); if (!gpu && !cpu && !accelerator) return CL_INVALID_DEVICE_TYPE; diff --git a/src/core/device.cpp b/src/core/device.cpp index c300f79..20e6f2b 100644 --- a/src/core/device.cpp +++ b/src/core/device.cpp @@ -39,9 +39,12 @@ Device * Device::create(cl_uint type) static void stringToParam(const std::string &str, void * paramValue, + size_t paramValueSize, size_t * paramValueSizeRet) { - strcpy((char*)paramValue, str.c_str()); + char *paramCharValue = (char *)paramValue; + paramCharValue[paramValueSize - 1] = 0; + strncpy(paramCharValue, str.c_str(), paramValueSize - 1); if (paramValueSizeRet) *paramValueSizeRet = str.size(); } @@ -51,8 +54,14 @@ cl_int Device::info(cl_device_info opcode, void * paramValue, size_t * paramValueSizeRet) const { + if (!paramValue) + return CL_SUCCESS; + switch (opcode) { case CL_DEVICE_TYPE: + if (paramValueSizeRet) + *paramValueSizeRet = sizeof(type()); + ((cl_int*)paramValue)[0] = type(); break; case CL_DEVICE_VENDOR_ID: @@ -140,10 +149,10 @@ cl_int Device::info(cl_device_info opcode, case CL_DEVICE_QUEUE_PROPERTIES: break; case CL_DEVICE_NAME: - stringToParam(m_info.name, paramValue, paramValueSizeRet); + stringToParam(m_info.name, paramValue, paramValueSize, paramValueSizeRet); break; case CL_DEVICE_VENDOR: - stringToParam(m_info.name, paramValue, paramValueSizeRet); + stringToParam(m_info.name, paramValue, paramValueSize, paramValueSizeRet); break; case CL_DRIVER_VERSION: break; @@ -159,6 +168,9 @@ cl_int Device::info(cl_device_info opcode, break; } + if (paramValueSizeRet && paramValueSize != *paramValueSizeRet) + return CL_INVALID_VALUE; + return CL_SUCCESS; }
------------------------------------------------------------------------------ This SF.Net email is sponsored by the Verizon Developer Community Take advantage of Verizon's best-in-class app development support A streamlined, 14 day to market process makes app distribution fast and easy Join now and get one step closer to millions of Verizon customers http://p.sf.net/sfu/verizon-dev2dev
_______________________________________________ Mesa3d-dev mailing list Mesa3d-dev@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mesa3d-dev