Skip to content

Commit b999657

Browse files
[SYCL][NFC] Minor Coverity fixes (#19460)
This PR makes the following changes: 1. Use `std::move` instead of copy 2. Handle integer overflow in `registerStream` and `registerVendor`
1 parent 4d0e89e commit b999657

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

sycl/source/detail/context_impl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ namespace detail {
3232
context_impl::context_impl(const std::vector<sycl::device> Devices,
3333
async_handler AsyncHandler,
3434
const property_list &PropList, private_tag)
35-
: MOwnedByRuntime(true), MAsyncHandler(AsyncHandler), MDevices(Devices),
36-
MContext(nullptr),
35+
: MOwnedByRuntime(true), MAsyncHandler(std::move(AsyncHandler)),
36+
MDevices(std::move(Devices)), MContext(nullptr),
3737
MPlatform(detail::getSyclObjImpl(MDevices[0].get_platform())),
3838
MPropList(PropList), MSupportBufferLocationByDevices(NotChecked) {
3939
verifyProps(PropList);

sycl/source/detail/helpers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const RTDeviceBinaryImage *retrieveKernelBinary(queue_impl &Queue,
4747
bool isHIP = Dev.getBackend() == backend::ext_oneapi_hip;
4848
if (isNvidia || isHIP) {
4949
auto KernelID = ProgramManager::getInstance().getSYCLKernelID(KernelName);
50-
std::vector<kernel_id> KernelIds{KernelID};
50+
std::vector<kernel_id> KernelIds{std::move(KernelID)};
5151
auto DeviceImages =
5252
ProgramManager::getInstance().getRawDeviceImages(KernelIds);
5353
auto DeviceImage = std::find_if(

xptifw/src/xpti_trace_framework.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,7 +2256,17 @@ class Framework {
22562256
}
22572257

22582258
uint8_t registerStream(const char *StreamName) {
2259-
return (uint8_t)MStreamStringTable.add(StreamName);
2259+
xpti::string_id_t StreamID = MStreamStringTable.add(StreamName);
2260+
2261+
// string_id_t is uint32_t while return type is uint8_t, so we need to
2262+
// check if the ID is valid and fits into uint8_t.
2263+
if (StreamID == xpti::invalid_id<xpti::string_id_t>)
2264+
return xpti::invalid_id<uint8_t>;
2265+
else {
2266+
assert(StreamID < std::numeric_limits<uint8_t>::max() &&
2267+
"StreamID exceeds the maximum value for uint8_t");
2268+
return static_cast<uint8_t>(StreamID);
2269+
}
22602270
}
22612271

22622272
///
@@ -2284,7 +2294,17 @@ class Framework {
22842294
}
22852295

22862296
uint8_t registerVendor(const char *StreamName) {
2287-
return (uint8_t)MVendorStringTable.add(StreamName);
2297+
xpti::string_id_t StreamID = MVendorStringTable.add(StreamName);
2298+
2299+
// string_id_t is uint32_t while return type is uint8_t, so we need to
2300+
// check if the ID is valid and fits into uint8_t.
2301+
if (StreamID == xpti::invalid_id<xpti::string_id_t>)
2302+
return xpti::invalid_id<uint8_t>;
2303+
else {
2304+
assert(StreamID < std::numeric_limits<uint8_t>::max() &&
2305+
"StreamID exceeds the maximum value for uint8_t");
2306+
return static_cast<uint8_t>(StreamID);
2307+
}
22882308
}
22892309

22902310
string_id_t registerString(const char *String, char **TableString) {

0 commit comments

Comments
 (0)