Skip to content

Fix unconditional panic warnings #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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