Skip to content

Commit

Permalink
Merge pull request #30 from Shnatsel/fix-unsound-prefix
Browse files Browse the repository at this point in the history
Drop unsafe code from currently unsound function prefix()
  • Loading branch information
sile authored May 27, 2019
2 parents 14c7627 + 55c89a9 commit 4c9de73
Showing 1 changed file with 3 additions and 8 deletions.
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

0 comments on commit 4c9de73

Please sign in to comment.