Skip to content

Commit

Permalink
Add missing checks when converting slices to views
Browse files Browse the repository at this point in the history
  • Loading branch information
jturner314 committed Dec 7, 2021
1 parent 1a7c020 commit 1fb2f42
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/arraytraits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ impl<'a, A, const N: usize> From<&'a [[A; N]]> for ArrayView<'a, A, Ix2> {
if size_of::<A>() == 0 {
dimension::size_of_shape_checked(&dim)
.expect("Product of non-zero axis lengths must not overflow isize.");
} else if N == 0 {
assert!(
xs.len() <= isize::MAX as usize,
"Product of non-zero axis lengths must not overflow isize.",
);
}

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

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

0 comments on commit 1fb2f42

Please sign in to comment.