Skip to content

Commit 8d934d6

Browse files
authored
Merge pull request #544 from PatKamin/coverity-issues
[coverity] Fix Coverity issues
2 parents b3accb9 + ae2c798 commit 8d934d6

File tree

15 files changed

+92
-84
lines changed

15 files changed

+92
-84
lines changed

.github/workflows/coverity.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ env:
1818
COVERITY_SCAN_NOTIFICATION_EMAIL: ${{ secrets.COVERITY_SCAN_NOTIFICATION_EMAIL }}
1919
COVERITY_SCAN_TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
2020
COVERITY_SCAN_PROJECT_NAME: ${{ github.repository }}
21-
COVERITY_SCAN_BUILD_COMMAND: "make"
21+
COVERITY_SCAN_BUILD_COMMAND: "cmake --build ${{github.workspace}}/build"
2222
COVERITY_SCAN_BRANCH_PATTERN: "main"
2323
TRAVIS_BRANCH: ${{ github.ref_name }}
2424

examples/collector/collector.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ XPTI_CALLBACK_API void xptiTraceInit(unsigned int major_version,
113113
unsigned int minor_version,
114114
const char *version_str,
115115
const char *stream_name) {
116-
if (!stream_name || std::string_view(stream_name) != UR_STREAM_NAME) {
116+
if (stream_name == nullptr) {
117+
std::cout << "Stream name not provided. Aborting." << std::endl;
118+
return;
119+
}
120+
if (std::string_view(stream_name) != UR_STREAM_NAME) {
117121
std::cout << "Invalid stream name: " << stream_name << ". Expected "
118122
<< UR_STREAM_NAME << ". Aborting." << std::endl;
119123
return;

scripts/templates/ldrddi.cpp.mako

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ namespace ur_loader
127127
auto ${item['name']}Local = new ${item['type']} [${item['range'][1]}];
128128
<%
129129
arrays_to_delete.append(item['name']+ 'Local')
130-
%>for( size_t i = ${item['range'][0]}; ( nullptr != ${item['name']} ) && ( i < ${item['range'][1]} ); ++i )
130+
%>for( size_t i = ${item['range'][0]}; i < ${item['range'][1]}; ++i )
131131
${item['name']}Local[ i ] = reinterpret_cast<${item['obj']}*>( ${item['name']}[ i ] )->handle;
132132
%else:
133133
// convert loader handle to platform handle

scripts/templates/ldrddi.hpp.mako

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ from templates import helper as th
2222
#define UR_LOADER_LDRDDI_H 1
2323

2424
#include "${x}_object.hpp"
25+
#include "${x}_singleton.hpp"
2526

2627
namespace ur_loader
2728
{

source/common/logger/ur_logger_details.hpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,20 @@ namespace logger {
1414
class Logger {
1515
public:
1616
Logger(std::unique_ptr<logger::Sink> sink) : sink(std::move(sink)) {
17-
if (!this->sink) {
18-
throw std::invalid_argument(
19-
"Can't create logger with nullptr Sink!");
20-
}
2117
this->level = logger::Level::QUIET;
2218
}
2319

2420
Logger(logger::Level level, std::unique_ptr<logger::Sink> sink)
25-
: level(level), sink(std::move(sink)) {
26-
if (!this->sink) {
27-
throw std::invalid_argument(
28-
"Can't create logger with nullptr Sink!");
29-
}
30-
}
21+
: level(level), sink(std::move(sink)) {}
3122

3223
~Logger() = default;
3324

3425
void setLevel(logger::Level level) { this->level = level; }
3526

3627
void setFlushLevel(logger::Level level) {
37-
this->sink->setFlushLevel(level);
28+
if (sink) {
29+
this->sink->setFlushLevel(level);
30+
}
3831
}
3932

4033
template <typename... Args> void debug(const char *format, Args &&...args) {
@@ -64,7 +57,9 @@ class Logger {
6457
return;
6558
}
6659

67-
sink->log(level, format, std::forward<Args>(args)...);
60+
if (sink) {
61+
sink->log(level, format, std::forward<Args>(args)...);
62+
}
6863
}
6964

7065
private:

source/common/unified_memory_allocation/src/memory_tracker.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ static enum uma_result_t trackingAlloc(void *hProvider, size_t size,
108108
(uma_tracking_memory_provider_t *)hProvider;
109109
enum uma_result_t ret = UMA_RESULT_SUCCESS;
110110

111+
if (!p->hUpstream) {
112+
return UMA_RESULT_ERROR_INVALID_ARGUMENT;
113+
}
114+
111115
ret = umaMemoryProviderAlloc(p->hUpstream, size, alignment, ptr);
112116
if (ret != UMA_RESULT_SUCCESS) {
113117
return ret;

source/common/ur_singleton.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ template <typename singleton_tn, typename key_tn> class singleton_factory_t {
4747
/// the params are forwarded to the ctor of the singleton
4848
/// the first parameter must be the unique identifier of the instance
4949
template <typename... Ts> singleton_tn *getInstance(Ts &&...params) {
50-
auto key = getKey(std::forward<Ts>(params)...);
50+
auto key = getKey(params...);
5151

5252
if (key == 0) { // No zero keys allowed in map
5353
return static_cast<singleton_tn *>(0);

source/loader/ur_ldrddi.cpp

Lines changed: 28 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ __urdlllocal ur_result_t UR_APICALL urContextCreate(
676676

677677
// convert loader handles to platform handles
678678
auto phDevicesLocal = new ur_device_handle_t[DeviceCount];
679-
for (size_t i = 0; (nullptr != phDevices) && (i < DeviceCount); ++i) {
679+
for (size_t i = 0; i < DeviceCount; ++i) {
680680
phDevicesLocal[i] =
681681
reinterpret_cast<ur_device_object_t *>(phDevices[i])->handle;
682682
}
@@ -849,7 +849,7 @@ __urdlllocal ur_result_t UR_APICALL urContextCreateWithNativeHandle(
849849

850850
// convert loader handles to platform handles
851851
auto phDevicesLocal = new ur_device_handle_t[numDevices];
852-
for (size_t i = 0; (nullptr != phDevices) && (i < numDevices); ++i) {
852+
for (size_t i = 0; i < numDevices; ++i) {
853853
phDevicesLocal[i] =
854854
reinterpret_cast<ur_device_object_t *>(phDevices[i])->handle;
855855
}
@@ -1933,7 +1933,7 @@ __urdlllocal ur_result_t UR_APICALL urProgramLink(
19331933

19341934
// convert loader handles to platform handles
19351935
auto phProgramsLocal = new ur_program_handle_t[count];
1936-
for (size_t i = 0; (nullptr != phPrograms) && (i < count); ++i) {
1936+
for (size_t i = 0; i < count; ++i) {
19371937
phProgramsLocal[i] =
19381938
reinterpret_cast<ur_program_object_t *>(phPrograms[i])->handle;
19391939
}
@@ -3036,7 +3036,7 @@ __urdlllocal ur_result_t UR_APICALL urEventWait(
30363036

30373037
// convert loader handles to platform handles
30383038
auto phEventWaitListLocal = new ur_event_handle_t[numEvents];
3039-
for (size_t i = 0; (nullptr != phEventWaitList) && (i < numEvents); ++i) {
3039+
for (size_t i = 0; i < numEvents; ++i) {
30403040
phEventWaitListLocal[i] =
30413041
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
30423042
}
@@ -3252,8 +3252,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueKernelLaunch(
32523252

32533253
// convert loader handles to platform handles
32543254
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
3255-
for (size_t i = 0;
3256-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
3255+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
32573256
phEventWaitListLocal[i] =
32583257
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
32593258
}
@@ -3310,8 +3309,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueEventsWait(
33103309

33113310
// convert loader handles to platform handles
33123311
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
3313-
for (size_t i = 0;
3314-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
3312+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
33153313
phEventWaitListLocal[i] =
33163314
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
33173315
}
@@ -3368,8 +3366,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueEventsWaitWithBarrier(
33683366

33693367
// convert loader handles to platform handles
33703368
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
3371-
for (size_t i = 0;
3372-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
3369+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
33733370
phEventWaitListLocal[i] =
33743371
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
33753372
}
@@ -3432,8 +3429,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueMemBufferRead(
34323429

34333430
// convert loader handles to platform handles
34343431
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
3435-
for (size_t i = 0;
3436-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
3432+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
34373433
phEventWaitListLocal[i] =
34383434
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
34393435
}
@@ -3498,8 +3494,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueMemBufferWrite(
34983494

34993495
// convert loader handles to platform handles
35003496
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
3501-
for (size_t i = 0;
3502-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
3497+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
35033498
phEventWaitListLocal[i] =
35043499
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
35053500
}
@@ -3575,8 +3570,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueMemBufferReadRect(
35753570

35763571
// convert loader handles to platform handles
35773572
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
3578-
for (size_t i = 0;
3579-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
3573+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
35803574
phEventWaitListLocal[i] =
35813575
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
35823576
}
@@ -3656,8 +3650,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueMemBufferWriteRect(
36563650

36573651
// convert loader handles to platform handles
36583652
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
3659-
for (size_t i = 0;
3660-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
3653+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
36613654
phEventWaitListLocal[i] =
36623655
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
36633656
}
@@ -3725,8 +3718,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueMemBufferCopy(
37253718

37263719
// convert loader handles to platform handles
37273720
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
3728-
for (size_t i = 0;
3729-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
3721+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
37303722
phEventWaitListLocal[i] =
37313723
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
37323724
}
@@ -3802,8 +3794,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueMemBufferCopyRect(
38023794

38033795
// convert loader handles to platform handles
38043796
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
3805-
for (size_t i = 0;
3806-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
3797+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
38073798
phEventWaitListLocal[i] =
38083799
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
38093800
}
@@ -3868,8 +3859,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueMemBufferFill(
38683859

38693860
// convert loader handles to platform handles
38703861
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
3871-
for (size_t i = 0;
3872-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
3862+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
38733863
phEventWaitListLocal[i] =
38743864
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
38753865
}
@@ -3938,8 +3928,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueMemImageRead(
39383928

39393929
// convert loader handles to platform handles
39403930
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
3941-
for (size_t i = 0;
3942-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
3931+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
39433932
phEventWaitListLocal[i] =
39443933
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
39453934
}
@@ -4009,8 +3998,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueMemImageWrite(
40093998

40103999
// convert loader handles to platform handles
40114000
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
4012-
for (size_t i = 0;
4013-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
4001+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
40144002
phEventWaitListLocal[i] =
40154003
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
40164004
}
@@ -4083,8 +4071,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueMemImageCopy(
40834071

40844072
// convert loader handles to platform handles
40854073
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
4086-
for (size_t i = 0;
4087-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
4074+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
40884075
phEventWaitListLocal[i] =
40894076
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
40904077
}
@@ -4150,8 +4137,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueMemBufferMap(
41504137

41514138
// convert loader handles to platform handles
41524139
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
4153-
for (size_t i = 0;
4154-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
4140+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
41554141
phEventWaitListLocal[i] =
41564142
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
41574143
}
@@ -4213,8 +4199,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueMemUnmap(
42134199

42144200
// convert loader handles to platform handles
42154201
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
4216-
for (size_t i = 0;
4217-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
4202+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
42184203
phEventWaitListLocal[i] =
42194204
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
42204205
}
@@ -4277,8 +4262,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueUSMFill(
42774262

42784263
// convert loader handles to platform handles
42794264
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
4280-
for (size_t i = 0;
4281-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
4265+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
42824266
phEventWaitListLocal[i] =
42834267
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
42844268
}
@@ -4337,8 +4321,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueUSMMemcpy(
43374321

43384322
// convert loader handles to platform handles
43394323
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
4340-
for (size_t i = 0;
4341-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
4324+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
43424325
phEventWaitListLocal[i] =
43434326
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
43444327
}
@@ -4396,8 +4379,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueUSMPrefetch(
43964379

43974380
// convert loader handles to platform handles
43984381
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
4399-
for (size_t i = 0;
4400-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
4382+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
44014383
phEventWaitListLocal[i] =
44024384
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
44034385
}
@@ -4507,8 +4489,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueUSMFill2D(
45074489

45084490
// convert loader handles to platform handles
45094491
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
4510-
for (size_t i = 0;
4511-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
4492+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
45124493
phEventWaitListLocal[i] =
45134494
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
45144495
}
@@ -4573,8 +4554,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueUSMMemcpy2D(
45734554

45744555
// convert loader handles to platform handles
45754556
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
4576-
for (size_t i = 0;
4577-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
4557+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
45784558
phEventWaitListLocal[i] =
45794559
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
45804560
}
@@ -4643,8 +4623,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueDeviceGlobalVariableWrite(
46434623

46444624
// convert loader handles to platform handles
46454625
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
4646-
for (size_t i = 0;
4647-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
4626+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
46484627
phEventWaitListLocal[i] =
46494628
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
46504629
}
@@ -4713,8 +4692,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueDeviceGlobalVariableRead(
47134692

47144693
// convert loader handles to platform handles
47154694
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
4716-
for (size_t i = 0;
4717-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
4695+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
47184696
phEventWaitListLocal[i] =
47194697
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
47204698
}
@@ -4786,8 +4764,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueReadHostPipe(
47864764

47874765
// convert loader handles to platform handles
47884766
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
4789-
for (size_t i = 0;
4790-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
4767+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
47914768
phEventWaitListLocal[i] =
47924769
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
47934770
}
@@ -4859,8 +4836,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueWriteHostPipe(
48594836

48604837
// convert loader handles to platform handles
48614838
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
4862-
for (size_t i = 0;
4863-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
4839+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
48644840
phEventWaitListLocal[i] =
48654841
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
48664842
}

source/loader/ur_ldrddi.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define UR_LOADER_LDRDDI_H 1
1414

1515
#include "ur_object.hpp"
16+
#include "ur_singleton.hpp"
1617

1718
namespace ur_loader {
1819
///////////////////////////////////////////////////////////////////////////////

source/loader/ur_object.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#define UR_OBJECT_H 1
1515

1616
#include "ur_ddi.h"
17-
#include "ur_singleton.hpp"
1817
#include "ur_util.hpp"
1918

2019
//////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)