Skip to content

Commit bf5de8e

Browse files
author
Diptorup Deb
committed
Add missing extra checks to ensure unwrapped pointer is not Null.
1 parent 227a126 commit bf5de8e

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

dpctl-capi/source/dpctl_sycl_queue_interface.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -294,14 +294,18 @@ bool DPCTLQueue_AreEq(__dpctl_keep const DPCTLSyclQueueRef QRef1,
294294
DPCTLSyclBackendType DPCTLQueue_GetBackend(__dpctl_keep DPCTLSyclQueueRef QRef)
295295
{
296296
auto Q = unwrap(QRef);
297-
try {
298-
auto C = Q->get_context();
299-
return DPCTLContext_GetBackend(wrap(&C));
300-
} catch (runtime_error &re) {
301-
std::cerr << re.what() << '\n';
302-
// store error message
303-
return DPCTL_UNKNOWN_BACKEND;
297+
if (Q) {
298+
try {
299+
auto C = Q->get_context();
300+
return DPCTLContext_GetBackend(wrap(&C));
301+
} catch (runtime_error &re) {
302+
std::cerr << re.what() << '\n';
303+
// store error message
304+
return DPCTL_UNKNOWN_BACKEND;
305+
}
304306
}
307+
else
308+
return DPCTL_UNKNOWN_BACKEND;
305309
}
306310

307311
__dpctl_give DPCTLSyclDeviceRef
@@ -327,8 +331,13 @@ __dpctl_give DPCTLSyclContextRef
327331
DPCTLQueue_GetContext(__dpctl_keep const DPCTLSyclQueueRef QRef)
328332
{
329333
auto Q = unwrap(QRef);
330-
auto Context = new context(Q->get_context());
331-
return wrap(Context);
334+
DPCTLSyclContextRef CRef = nullptr;
335+
if (Q)
336+
CRef = wrap(new context(Q->get_context()));
337+
else {
338+
std::cerr << "Could not get the context for this queue.\n";
339+
}
340+
return CRef;
332341
}
333342

334343
__dpctl_give DPCTLSyclEventRef

0 commit comments

Comments
 (0)