Skip to content

Commit

Permalink
Merge pull request #1203 from pbalcer/random-coverity-issues
Browse files Browse the repository at this point in the history
[cuda][null][common] fix a few coverity issues
  • Loading branch information
wlemkows authored and kbenzie committed Jan 16, 2024
1 parent 7b5f58b commit c9d4810
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
5 changes: 4 additions & 1 deletion source/adapters/cuda/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion source/adapters/cuda/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "context.hpp"
#include "device.hpp"
#include "queue.hpp"
#include "ur_api.h"
#include "ur_util.hpp"

#include <cassert>
#include <cuda.h>
Expand Down Expand Up @@ -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;
}
Expand All @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion source/adapters/cuda/sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions source/adapters/null/ur_null.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions source/common/ur_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit c9d4810

Please sign in to comment.