Skip to content

Commit

Permalink
Use checked_mul instead of raw multiplication. Fixes #11
Browse files Browse the repository at this point in the history
  • Loading branch information
ejmahler committed Feb 20, 2024
1 parent e70dd15 commit c4bcd39
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/in_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn multiplicative_inverse(a: usize, n: usize) -> usize {
///
/// Panics if `input.len() != input_width * input_height` or if `output.len() != input_width * input_height`
pub fn transpose_inplace<T: Copy>(buffer: &mut [T], scratch: &mut [T], width: usize, height: usize) {
assert_eq!(width*height, buffer.len());
assert_eq!(width.checked_mul(height), Some(buffer.len()));
assert_eq!(core::cmp::max(width, height), scratch.len());

let gcd = StrengthReducedUsize::new(num_integer::gcd(width, height));
Expand Down
4 changes: 2 additions & 2 deletions src/out_of_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ fn transpose_recursive<T: Copy>(input: &[T], output: &mut [T], row_start: usize,
///
/// Panics if `input.len() != input_width * input_height` or if `output.len() != input_width * input_height`
pub fn transpose<T: Copy>(input: &[T], output: &mut [T], input_width: usize, input_height: usize) {
assert_eq!(input_width*input_height, input.len());
assert_eq!(input_width*input_height, output.len());
assert_eq!(input_width.checked_mul(input_height), Some(input.len()));
assert_eq!(input.len(), output.len());
if input.len() <= SMALL_LEN {
unsafe { transpose_small(input, output, input_width, input_height) };
}
Expand Down

0 comments on commit c4bcd39

Please sign in to comment.