Skip to content

Commit

Permalink
fn AlignedVec::resize: Use .expect of let else panic!.
Browse files Browse the repository at this point in the history
  • Loading branch information
kkysen committed Sep 23, 2024
1 parent c267131 commit 9464e27
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,12 @@ impl<T: Copy, C: AlignedByteChunk> AlignedVec<T, C> {
let old_len = self.len();

// Resize the underlying vector to have enough chunks for the new length.
// SAFETY: The `new_bytes` calculation must not overflow, ensuring a mathematical match
// with the underlying `inner` buffer size. NOTE: one can still pass ludicrous requested
// buffer lengths, just not unsound ones.
let Some(new_bytes) = mem::size_of::<T>().checked_mul(new_len) else {
panic!("Resizing would overflow the underlying aligned buffer");
};
// SAFETY: The `new_bytes` calculation must not overflow,
// ensuring a mathematical match with the underlying `inner` buffer size.
// NOTE: one can still pass ludicrous requested buffer lengths, just not unsound ones.
let new_bytes = mem::size_of::<T>()
.checked_mul(new_len)
.expect("Resizing would overflow the underlying aligned buffer");

let chunk_size = mem::size_of::<C>();
let new_chunks = if (new_bytes % chunk_size) == 0 {
Expand Down

0 comments on commit 9464e27

Please sign in to comment.