Skip to content

Commit 1fb2f42

Browse files
committed
Add missing checks when converting slices to views
1 parent 1a7c020 commit 1fb2f42

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/arraytraits.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@ impl<'a, A, const N: usize> From<&'a [[A; N]]> for ArrayView<'a, A, Ix2> {
336336
if size_of::<A>() == 0 {
337337
dimension::size_of_shape_checked(&dim)
338338
.expect("Product of non-zero axis lengths must not overflow isize.");
339+
} else if N == 0 {
340+
assert!(
341+
xs.len() <= isize::MAX as usize,
342+
"Product of non-zero axis lengths must not overflow isize.",
343+
);
339344
}
340345

341346
// `cols * rows` is guaranteed to fit in `isize` because we checked that it fits in
@@ -392,6 +397,11 @@ impl<'a, A, const N: usize> From<&'a mut [[A; N]]> for ArrayViewMut<'a, A, Ix2>
392397
if size_of::<A>() == 0 {
393398
dimension::size_of_shape_checked(&dim)
394399
.expect("Product of non-zero axis lengths must not overflow isize.");
400+
} else if N == 0 {
401+
assert!(
402+
xs.len() <= isize::MAX as usize,
403+
"Product of non-zero axis lengths must not overflow isize.",
404+
);
395405
}
396406

397407
// `cols * rows` is guaranteed to fit in `isize` because we checked that it fits in

0 commit comments

Comments
 (0)