Skip to content

Commit 70c6772

Browse files
committed
Re-order conditional strides assignment
Avoids possible out-of-bounds access by short-circuiting the if statement
1 parent 1544e9b commit 70c6772

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

dpctl/tensor/_dlpack.pyx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,10 @@ cpdef numpy_to_dlpack_versioned_capsule(ndarray npy_ary, bint copied):
562562
dl_tensor.ndim = nd
563563
dl_tensor.byte_offset = <uint64_t>byte_offset
564564
dl_tensor.shape = &shape_strides_ptr[0]
565-
dl_tensor.strides = &shape_strides_ptr[nd] if not is_c_contiguous else NULL
565+
if is_c_contiguous:
566+
dl_tensor.strides = NULL
567+
else:
568+
dl_tensor.strides = &shape_strides_ptr[nd]
566569
dl_tensor.device.device_type = kDLCPU
567570
dl_tensor.device.device_id = 0
568571
dl_tensor.dtype.lanes = <uint16_t>1

0 commit comments

Comments
 (0)