diff options
author | Igor Oliveira <igor.oliveira@openbossa.org> | 2010-01-04 09:23:56 -0500 |
---|---|---|
committer | Zack Rusin <zackr@vmware.com> | 2010-01-04 09:23:56 -0500 |
commit | a1b6c6bf448a6dbe2f1b668f319a251c0af57573 (patch) | |
tree | 66d0b111170faa3d915a17bb6674a9cec6a062f0 | |
parent | f179cb825c9d29abe27b978a88d504737aacdca5 (diff) |
Fix some bugs found by the unit tests.
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 .
-rw-r--r-- | src/api/api_device.cpp | 6 | ||||
-rw-r--r-- | src/core/device.cpp | 18 |
2 files changed, 18 insertions, 6 deletions
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; } |