Skip to content

Commit

Permalink
use assert! to verify length number
Browse files Browse the repository at this point in the history
  • Loading branch information
nylonicious committed Jan 8, 2025
1 parent cce13fa commit 6e61fc9
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/protocol/frame/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,9 @@ impl FrameHeader {
let length_length = LengthFormat::for_byte(length_byte).extra_bytes();
if length_length > 0 {
const SIZE: usize = mem::size_of::<u64>();
assert!(length_length <= SIZE, "length exceeded size of u64");
let start = SIZE - length_length;
let mut buffer = [0; SIZE];
let start = match SIZE.checked_sub(length_length) {
Some(start) => start,
None => {
panic!("the integer can fit {} bytes, but {} is given", SIZE, length_length)
}
};
match cursor.read_exact(&mut buffer[start..]) {
Err(ref err) if err.kind() == ErrorKind::UnexpectedEof => return Ok(None),
Err(err) => return Err(err.into()),
Expand Down

0 comments on commit 6e61fc9

Please sign in to comment.