Skip to content
New issue

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

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

Already on GitHub? # to your account

Drop unsafe code from currently unsound function prefix() #30

Merged
merged 1 commit into from
May 27, 2019
Merged
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
11 changes: 3 additions & 8 deletions src/lz77/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,9 @@ impl Lz77Encode for DefaultLz77Encoder {
}

#[inline]
fn prefix(buf: &[u8]) -> [u8; 3] {
unsafe {
[
*buf.get_unchecked(0),
*buf.get_unchecked(1),
*buf.get_unchecked(2),
]
}
fn prefix(input_buf: &[u8]) -> [u8; 3] {
let buf: &[u8] = &input_buf[..3]; // perform bounds check once
[buf[0], buf[1], buf[2]]
}

#[inline]
Expand Down