Skip to content

Commit

Permalink
Fix unconditional panic warnings (#71)
Browse files Browse the repository at this point in the history
We can just use `.get_unsafe()` here. Drive-by-fix: clippy warning. Drive-by-fix: clippy warning.

Fixes #68.
  • Loading branch information
hkratz authored Jan 8, 2023
1 parent 3578e32 commit 223385d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
18 changes: 8 additions & 10 deletions src/implementation/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,21 +181,19 @@ macro_rules! algorithm_simd {

#[cfg_attr(not(target_arch="aarch64"), target_feature(enable = $feat))]
#[inline]
#[allow(unconditional_panic)] // does not panic because len is checked
#[allow(const_err)] // the same, but for Rust 1.38.0
unsafe fn check_block(&mut self, input: SimdInput) {
// WORKAROUND
// necessary because the for loop is not unrolled on ARM64
if input.vals.len() == 2 {
self.check_bytes(input.vals[0]);
self.check_bytes(input.vals[1]);
self.incomplete = Self::is_incomplete(input.vals[1]);
self.check_bytes(*input.vals.get_unchecked(0));
self.check_bytes(*input.vals.get_unchecked(1));
self.incomplete = Self::is_incomplete(*input.vals.get_unchecked(1));
} else if input.vals.len() == 4 {
self.check_bytes(input.vals[0]);
self.check_bytes(input.vals[1]);
self.check_bytes(input.vals[2]);
self.check_bytes(input.vals[3]);
self.incomplete = Self::is_incomplete(input.vals[3]);
self.check_bytes(*input.vals.get_unchecked(0));
self.check_bytes(*input.vals.get_unchecked(1));
self.check_bytes(*input.vals.get_unchecked(2));
self.check_bytes(*input.vals.get_unchecked(3));
self.incomplete = Self::is_incomplete(*input.vals.get_unchecked(3));
} else {
panic!("Unsupported number of chunks");
}
Expand Down
1 change: 0 additions & 1 deletion src/implementation/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ pub(crate) fn get_compat_error(input: &[u8], failing_block_pos: usize) -> Utf8Er
// UTF-8 codepoint, is thus complete and valid UTF-8. We start the check with the
// current block in that case.
(1..=3)
.into_iter()
.find(|i| input[failing_block_pos - i] >> 6 != 0b10)
.map_or(failing_block_pos, |i| failing_block_pos - i)
};
Expand Down

0 comments on commit 223385d

Please sign in to comment.