From c9d48102eff4500910dbcb37d62157c55ef72d54 Mon Sep 17 00:00:00 2001 From: Weronika Lewandowska Date: Wed, 20 Dec 2023 11:17:05 +0100 Subject: [PATCH] Merge pull request #1203 from pbalcer/random-coverity-issues [cuda][null][common] fix a few coverity issues --- source/adapters/cuda/device.cpp | 5 ++++- source/adapters/cuda/event.cpp | 6 +++++- source/adapters/cuda/sampler.cpp | 1 - source/adapters/null/ur_null.cpp | 4 ++-- source/common/ur_util.hpp | 2 ++ 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/source/adapters/cuda/device.cpp b/source/adapters/cuda/device.cpp index 8d95ad05e8..4875adfed1 100644 --- a/source/adapters/cuda/device.cpp +++ b/source/adapters/cuda/device.cpp @@ -16,6 +16,7 @@ #include "context.hpp" #include "device.hpp" #include "platform.hpp" +#include "ur_util.hpp" int getAttribute(ur_device_handle_t device, CUdevice_attribute attribute) { int value; @@ -40,7 +41,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, ur_device_info_t propName, size_t propSize, void *pPropValue, - size_t *pPropSizeRet) { + size_t *pPropSizeRet) try { UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet); static constexpr uint32_t MaxWorkItemDimensions = 3u; @@ -1033,6 +1034,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, break; } return UR_RESULT_ERROR_INVALID_ENUMERATION; +} catch (...) { + return exceptionToResult(std::current_exception()); } /// \return PI_SUCCESS if the function is executed successfully diff --git a/source/adapters/cuda/event.cpp b/source/adapters/cuda/event.cpp index 2cbfcbc39b..804b35a9b7 100644 --- a/source/adapters/cuda/event.cpp +++ b/source/adapters/cuda/event.cpp @@ -12,6 +12,8 @@ #include "context.hpp" #include "device.hpp" #include "queue.hpp" +#include "ur_api.h" +#include "ur_util.hpp" #include #include @@ -65,7 +67,7 @@ ur_result_t ur_event_handle_t_::start() { return Result; } -bool ur_event_handle_t_::isCompleted() const noexcept { +bool ur_event_handle_t_::isCompleted() const noexcept try { if (!IsRecorded) { return false; } @@ -80,6 +82,8 @@ bool ur_event_handle_t_::isCompleted() const noexcept { } } return true; +} catch (...) { + return exceptionToResult(std::current_exception()) == UR_RESULT_SUCCESS; } uint64_t ur_event_handle_t_::getQueuedTime() const { diff --git a/source/adapters/cuda/sampler.cpp b/source/adapters/cuda/sampler.cpp index 0e1305da23..ce4283edd3 100644 --- a/source/adapters/cuda/sampler.cpp +++ b/source/adapters/cuda/sampler.cpp @@ -71,7 +71,6 @@ urSamplerGetInfo(ur_sampler_handle_t hSampler, ur_sampler_info_t propName, default: return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION; } - return {}; } UR_APIEXPORT ur_result_t UR_APICALL diff --git a/source/adapters/null/ur_null.cpp b/source/adapters/null/ur_null.cpp index 5a62761b67..a64d46e4d4 100644 --- a/source/adapters/null/ur_null.cpp +++ b/source/adapters/null/ur_null.cpp @@ -173,7 +173,7 @@ context_t::context_t() { return UR_RESULT_ERROR_UNSUPPORTED_SIZE; } *ppMem = malloc(size); - if (ppMem == nullptr) { + if (*ppMem == nullptr) { return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY; } return UR_RESULT_SUCCESS; @@ -189,7 +189,7 @@ context_t::context_t() { return UR_RESULT_ERROR_UNSUPPORTED_SIZE; } *ppMem = malloc(size); - if (ppMem == nullptr) { + if (*ppMem == nullptr) { return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY; } return UR_RESULT_SUCCESS; diff --git a/source/common/ur_util.hpp b/source/common/ur_util.hpp index a73f348b52..00aaf8eee2 100644 --- a/source/common/ur_util.hpp +++ b/source/common/ur_util.hpp @@ -288,6 +288,8 @@ inline ur_result_t exceptionToResult(std::exception_ptr eptr) { return UR_RESULT_SUCCESS; } catch (std::bad_alloc &) { return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY; + } catch (const ur_result_t &e) { + return e; } catch (...) { return UR_RESULT_ERROR_UNKNOWN; }