Skip to content

Commit f2e0d0f

Browse files
authored
Merge pull request #1203 from pbalcer/random-coverity-issues
[cuda][null][common] fix a few coverity issues
2 parents 26875c4 + 7f5dfcc commit f2e0d0f

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
lines changed

source/adapters/cuda/device.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "context.hpp"
1717
#include "device.hpp"
1818
#include "platform.hpp"
19+
#include "ur_util.hpp"
1920

2021
int getAttribute(ur_device_handle_t device, CUdevice_attribute attribute) {
2122
int value;
@@ -40,7 +41,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
4041
ur_device_info_t propName,
4142
size_t propSize,
4243
void *pPropValue,
43-
size_t *pPropSizeRet) {
44+
size_t *pPropSizeRet) try {
4445
UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
4546

4647
static constexpr uint32_t MaxWorkItemDimensions = 3u;
@@ -1034,6 +1035,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
10341035
break;
10351036
}
10361037
return UR_RESULT_ERROR_INVALID_ENUMERATION;
1038+
} catch (...) {
1039+
return exceptionToResult(std::current_exception());
10371040
}
10381041

10391042
/// \return PI_SUCCESS if the function is executed successfully

source/adapters/cuda/event.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "context.hpp"
1313
#include "device.hpp"
1414
#include "queue.hpp"
15+
#include "ur_api.h"
16+
#include "ur_util.hpp"
1517

1618
#include <cassert>
1719
#include <cuda.h>
@@ -65,7 +67,7 @@ ur_result_t ur_event_handle_t_::start() {
6567
return Result;
6668
}
6769

68-
bool ur_event_handle_t_::isCompleted() const noexcept {
70+
bool ur_event_handle_t_::isCompleted() const noexcept try {
6971
if (!IsRecorded) {
7072
return false;
7173
}
@@ -80,6 +82,8 @@ bool ur_event_handle_t_::isCompleted() const noexcept {
8082
}
8183
}
8284
return true;
85+
} catch (...) {
86+
return exceptionToResult(std::current_exception()) == UR_RESULT_SUCCESS;
8387
}
8488

8589
uint64_t ur_event_handle_t_::getQueuedTime() const {

source/adapters/cuda/sampler.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ urSamplerGetInfo(ur_sampler_handle_t hSampler, ur_sampler_info_t propName,
7171
default:
7272
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
7373
}
74-
return {};
7574
}
7675

7776
UR_APIEXPORT ur_result_t UR_APICALL

source/adapters/null/ur_null.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ context_t::context_t() {
172172
return UR_RESULT_ERROR_UNSUPPORTED_SIZE;
173173
}
174174
*ppMem = malloc(size);
175-
if (ppMem == nullptr) {
175+
if (*ppMem == nullptr) {
176176
return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
177177
}
178178
return UR_RESULT_SUCCESS;
@@ -187,7 +187,7 @@ context_t::context_t() {
187187
return UR_RESULT_ERROR_UNSUPPORTED_SIZE;
188188
}
189189
*ppMem = malloc(size);
190-
if (ppMem == nullptr) {
190+
if (*ppMem == nullptr) {
191191
return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
192192
}
193193
return UR_RESULT_SUCCESS;

source/common/ur_util.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ inline ur_result_t exceptionToResult(std::exception_ptr eptr) {
288288
return UR_RESULT_SUCCESS;
289289
} catch (std::bad_alloc &) {
290290
return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
291+
} catch (const ur_result_t &e) {
292+
return e;
291293
} catch (...) {
292294
return UR_RESULT_ERROR_UNKNOWN;
293295
}

0 commit comments

Comments
 (0)