Skip to content

Commit ae2c798

Browse files
committed
Fix Coverity issues
1 parent 2ed1735 commit ae2c798

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
@@ -16,7 +16,7 @@ env:
1616
COVERITY_SCAN_NOTIFICATION_EMAIL: ${{ secrets.COVERITY_SCAN_NOTIFICATION_EMAIL }}
1717
COVERITY_SCAN_TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
1818
COVERITY_SCAN_PROJECT_NAME: ${{ github.repository }}
19-
COVERITY_SCAN_BUILD_COMMAND: "make"
19+
COVERITY_SCAN_BUILD_COMMAND: "cmake --build ${{github.workspace}}/build"
2020
COVERITY_SCAN_BRANCH_PATTERN: "main"
2121
TRAVIS_BRANCH: ${{ github.ref_name }}
2222

examples/collector/collector.cpp

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

scripts/templates/ldrddi.cpp.mako

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ namespace ur_loader
125125
auto ${item['name']}Local = new ${item['type']} [${item['range'][1]}];
126126
<%
127127
arrays_to_delete.append(item['name']+ 'Local')
128-
%>for( size_t i = ${item['range'][0]}; ( nullptr != ${item['name']} ) && ( i < ${item['range'][1]} ); ++i )
128+
%>for( size_t i = ${item['range'][0]}; i < ${item['range'][1]}; ++i )
129129
${item['name']}Local[ i ] = reinterpret_cast<${item['obj']}*>( ${item['name']}[ i ] )->handle;
130130
%else:
131131
// 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
@@ -20,6 +20,7 @@ from templates import helper as th
2020
#define UR_LOADER_LDRDDI_H 1
2121

2222
#include "${x}_object.hpp"
23+
#include "${x}_singleton.hpp"
2324

2425
namespace ur_loader
2526
{

source/common/logger/ur_logger_details.hpp

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

2218
Logger(logger::Level level, std::unique_ptr<logger::Sink> sink)
23-
: level(level), sink(std::move(sink)) {
24-
if (!this->sink) {
25-
throw std::invalid_argument(
26-
"Can't create logger with nullptr Sink!");
27-
}
28-
}
19+
: level(level), sink(std::move(sink)) {}
2920

3021
~Logger() = default;
3122

3223
void setLevel(logger::Level level) { this->level = level; }
3324

3425
void setFlushLevel(logger::Level level) {
35-
this->sink->setFlushLevel(level);
26+
if (sink) {
27+
this->sink->setFlushLevel(level);
28+
}
3629
}
3730

3831
template <typename... Args> void debug(const char *format, Args &&...args) {
@@ -62,7 +55,9 @@ class Logger {
6255
return;
6356
}
6457

65-
sink->log(level, format, std::forward<Args>(args)...);
58+
if (sink) {
59+
sink->log(level, format, std::forward<Args>(args)...);
60+
}
6661
}
6762

6863
private:

source/common/unified_memory_allocation/src/memory_tracker.cpp

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

109+
if (!p->hUpstream) {
110+
return UMA_RESULT_ERROR_INVALID_ARGUMENT;
111+
}
112+
109113
ret = umaMemoryProviderAlloc(p->hUpstream, size, alignment, ptr);
110114
if (ret != UMA_RESULT_SUCCESS) {
111115
return ret;

source/common/ur_singleton.hpp

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

5050
if (key == 0) { // No zero keys allowed in map
5151
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
@@ -673,7 +673,7 @@ __urdlllocal ur_result_t UR_APICALL urContextCreate(
673673

674674
// convert loader handles to platform handles
675675
auto phDevicesLocal = new ur_device_handle_t[DeviceCount];
676-
for (size_t i = 0; (nullptr != phDevices) && (i < DeviceCount); ++i) {
676+
for (size_t i = 0; i < DeviceCount; ++i) {
677677
phDevicesLocal[i] =
678678
reinterpret_cast<ur_device_object_t *>(phDevices[i])->handle;
679679
}
@@ -846,7 +846,7 @@ __urdlllocal ur_result_t UR_APICALL urContextCreateWithNativeHandle(
846846

847847
// convert loader handles to platform handles
848848
auto phDevicesLocal = new ur_device_handle_t[numDevices];
849-
for (size_t i = 0; (nullptr != phDevices) && (i < numDevices); ++i) {
849+
for (size_t i = 0; i < numDevices; ++i) {
850850
phDevicesLocal[i] =
851851
reinterpret_cast<ur_device_object_t *>(phDevices[i])->handle;
852852
}
@@ -1929,7 +1929,7 @@ __urdlllocal ur_result_t UR_APICALL urProgramLink(
19291929

19301930
// convert loader handles to platform handles
19311931
auto phProgramsLocal = new ur_program_handle_t[count];
1932-
for (size_t i = 0; (nullptr != phPrograms) && (i < count); ++i) {
1932+
for (size_t i = 0; i < count; ++i) {
19331933
phProgramsLocal[i] =
19341934
reinterpret_cast<ur_program_object_t *>(phPrograms[i])->handle;
19351935
}
@@ -3032,7 +3032,7 @@ __urdlllocal ur_result_t UR_APICALL urEventWait(
30323032

30333033
// convert loader handles to platform handles
30343034
auto phEventWaitListLocal = new ur_event_handle_t[numEvents];
3035-
for (size_t i = 0; (nullptr != phEventWaitList) && (i < numEvents); ++i) {
3035+
for (size_t i = 0; i < numEvents; ++i) {
30363036
phEventWaitListLocal[i] =
30373037
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
30383038
}
@@ -3248,8 +3248,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueKernelLaunch(
32483248

32493249
// convert loader handles to platform handles
32503250
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
3251-
for (size_t i = 0;
3252-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
3251+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
32533252
phEventWaitListLocal[i] =
32543253
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
32553254
}
@@ -3306,8 +3305,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueEventsWait(
33063305

33073306
// convert loader handles to platform handles
33083307
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
3309-
for (size_t i = 0;
3310-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
3308+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
33113309
phEventWaitListLocal[i] =
33123310
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
33133311
}
@@ -3364,8 +3362,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueEventsWaitWithBarrier(
33643362

33653363
// convert loader handles to platform handles
33663364
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
3367-
for (size_t i = 0;
3368-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
3365+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
33693366
phEventWaitListLocal[i] =
33703367
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
33713368
}
@@ -3428,8 +3425,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueMemBufferRead(
34283425

34293426
// convert loader handles to platform handles
34303427
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
3431-
for (size_t i = 0;
3432-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
3428+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
34333429
phEventWaitListLocal[i] =
34343430
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
34353431
}
@@ -3494,8 +3490,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueMemBufferWrite(
34943490

34953491
// convert loader handles to platform handles
34963492
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
3497-
for (size_t i = 0;
3498-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
3493+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
34993494
phEventWaitListLocal[i] =
35003495
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
35013496
}
@@ -3571,8 +3566,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueMemBufferReadRect(
35713566

35723567
// convert loader handles to platform handles
35733568
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
3574-
for (size_t i = 0;
3575-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
3569+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
35763570
phEventWaitListLocal[i] =
35773571
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
35783572
}
@@ -3652,8 +3646,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueMemBufferWriteRect(
36523646

36533647
// convert loader handles to platform handles
36543648
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
3655-
for (size_t i = 0;
3656-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
3649+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
36573650
phEventWaitListLocal[i] =
36583651
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
36593652
}
@@ -3721,8 +3714,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueMemBufferCopy(
37213714

37223715
// convert loader handles to platform handles
37233716
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
3724-
for (size_t i = 0;
3725-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
3717+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
37263718
phEventWaitListLocal[i] =
37273719
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
37283720
}
@@ -3798,8 +3790,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueMemBufferCopyRect(
37983790

37993791
// convert loader handles to platform handles
38003792
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
3801-
for (size_t i = 0;
3802-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
3793+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
38033794
phEventWaitListLocal[i] =
38043795
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
38053796
}
@@ -3864,8 +3855,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueMemBufferFill(
38643855

38653856
// convert loader handles to platform handles
38663857
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
3867-
for (size_t i = 0;
3868-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
3858+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
38693859
phEventWaitListLocal[i] =
38703860
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
38713861
}
@@ -3934,8 +3924,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueMemImageRead(
39343924

39353925
// convert loader handles to platform handles
39363926
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
3937-
for (size_t i = 0;
3938-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
3927+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
39393928
phEventWaitListLocal[i] =
39403929
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
39413930
}
@@ -4005,8 +3994,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueMemImageWrite(
40053994

40063995
// convert loader handles to platform handles
40073996
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
4008-
for (size_t i = 0;
4009-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
3997+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
40103998
phEventWaitListLocal[i] =
40113999
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
40124000
}
@@ -4079,8 +4067,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueMemImageCopy(
40794067

40804068
// convert loader handles to platform handles
40814069
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
4082-
for (size_t i = 0;
4083-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
4070+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
40844071
phEventWaitListLocal[i] =
40854072
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
40864073
}
@@ -4146,8 +4133,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueMemBufferMap(
41464133

41474134
// convert loader handles to platform handles
41484135
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
4149-
for (size_t i = 0;
4150-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
4136+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
41514137
phEventWaitListLocal[i] =
41524138
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
41534139
}
@@ -4209,8 +4195,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueMemUnmap(
42094195

42104196
// convert loader handles to platform handles
42114197
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
4212-
for (size_t i = 0;
4213-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
4198+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
42144199
phEventWaitListLocal[i] =
42154200
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
42164201
}
@@ -4273,8 +4258,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueUSMFill(
42734258

42744259
// convert loader handles to platform handles
42754260
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
4276-
for (size_t i = 0;
4277-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
4261+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
42784262
phEventWaitListLocal[i] =
42794263
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
42804264
}
@@ -4333,8 +4317,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueUSMMemcpy(
43334317

43344318
// convert loader handles to platform handles
43354319
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
4336-
for (size_t i = 0;
4337-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
4320+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
43384321
phEventWaitListLocal[i] =
43394322
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
43404323
}
@@ -4392,8 +4375,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueUSMPrefetch(
43924375

43934376
// convert loader handles to platform handles
43944377
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
4395-
for (size_t i = 0;
4396-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
4378+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
43974379
phEventWaitListLocal[i] =
43984380
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
43994381
}
@@ -4503,8 +4485,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueUSMFill2D(
45034485

45044486
// convert loader handles to platform handles
45054487
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
4506-
for (size_t i = 0;
4507-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
4488+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
45084489
phEventWaitListLocal[i] =
45094490
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
45104491
}
@@ -4569,8 +4550,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueUSMMemcpy2D(
45694550

45704551
// convert loader handles to platform handles
45714552
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
4572-
for (size_t i = 0;
4573-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
4553+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
45744554
phEventWaitListLocal[i] =
45754555
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
45764556
}
@@ -4639,8 +4619,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueDeviceGlobalVariableWrite(
46394619

46404620
// convert loader handles to platform handles
46414621
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
4642-
for (size_t i = 0;
4643-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
4622+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
46444623
phEventWaitListLocal[i] =
46454624
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
46464625
}
@@ -4709,8 +4688,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueDeviceGlobalVariableRead(
47094688

47104689
// convert loader handles to platform handles
47114690
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
4712-
for (size_t i = 0;
4713-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
4691+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
47144692
phEventWaitListLocal[i] =
47154693
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
47164694
}
@@ -4782,8 +4760,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueReadHostPipe(
47824760

47834761
// convert loader handles to platform handles
47844762
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
4785-
for (size_t i = 0;
4786-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
4763+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
47874764
phEventWaitListLocal[i] =
47884765
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
47894766
}
@@ -4855,8 +4832,7 @@ __urdlllocal ur_result_t UR_APICALL urEnqueueWriteHostPipe(
48554832

48564833
// convert loader handles to platform handles
48574834
auto phEventWaitListLocal = new ur_event_handle_t[numEventsInWaitList];
4858-
for (size_t i = 0;
4859-
(nullptr != phEventWaitList) && (i < numEventsInWaitList); ++i) {
4835+
for (size_t i = 0; i < numEventsInWaitList; ++i) {
48604836
phEventWaitListLocal[i] =
48614837
reinterpret_cast<ur_event_object_t *>(phEventWaitList[i])->handle;
48624838
}

source/loader/ur_ldrddi.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define UR_LOADER_LDRDDI_H 1
1212

1313
#include "ur_object.hpp"
14+
#include "ur_singleton.hpp"
1415

1516
namespace ur_loader {
1617
///////////////////////////////////////////////////////////////////////////////

source/loader/ur_object.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#define UR_OBJECT_H 1
1313

1414
#include "ur_ddi.h"
15-
#include "ur_singleton.hpp"
1615
#include "ur_util.hpp"
1716

1817
//////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)