Skip to content

Commit

Permalink
Clippy fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirbaio committed Nov 6, 2022
1 parent 9d86fb9 commit b92fc8f
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 23 deletions.
11 changes: 4 additions & 7 deletions src/iface/fragmentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ impl<'a, K: Eq + Ord + Clone + Copy> PacketAssemblerSet<'a, K> {
/// - Returns [`Error::PacketAssemblerSetKeyNotFound`] when the key was not found in the set.
pub(crate) fn get_packet_assembler_mut(&mut self, key: &K) -> Result<&mut PacketAssembler<'a>> {
if let Some(i) = self.index_buffer.get(key) {
Ok(&mut self.packet_buffer[*i as usize])
Ok(&mut self.packet_buffer[*i])
} else {
Err(Error::PacketAssemblerSetKeyNotFound)
}
Expand All @@ -379,7 +379,7 @@ impl<'a, K: Eq + Ord + Clone + Copy> PacketAssemblerSet<'a, K> {
/// - Returns [`Error::PacketAssemblerIncomplete`] when the fragments assembler was empty or not fully assembled.
pub(crate) fn get_assembled_packet(&mut self, key: &K) -> Result<&[u8]> {
if let Some(i) = self.index_buffer.get(key) {
let p = self.packet_buffer[*i as usize].assemble()?;
let p = self.packet_buffer[*i].assemble()?;
self.index_buffer.remove(key);
Ok(p)
} else {
Expand All @@ -392,10 +392,7 @@ impl<'a, K: Eq + Ord + Clone + Copy> PacketAssemblerSet<'a, K> {
loop {
let mut key = None;
for (k, i) in self.index_buffer.iter() {
if matches!(
self.packet_buffer[*i as usize].assembler,
AssemblerState::NotInit
) {
if matches!(self.packet_buffer[*i].assembler, AssemblerState::NotInit) {
key = Some(*k);
break;
}
Expand All @@ -416,7 +413,7 @@ impl<'a, K: Eq + Ord + Clone + Copy> PacketAssemblerSet<'a, K> {
F: Fn(&mut PacketAssembler<'_>) -> Result<bool>,
{
for (_, i) in &mut self.index_buffer.iter() {
let frag = &mut self.packet_buffer[*i as usize];
let frag = &mut self.packet_buffer[*i];
if f(frag)? {
frag.mark_discarded();
}
Expand Down
2 changes: 1 addition & 1 deletion src/iface/interface/ipv4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ impl<'a> InterfaceInner<'a> {
}

tx_buffer[repr.buffer_len()..][..payload_len].copy_from_slice(
&buffer[*frag_offset as usize + repr.buffer_len() as usize..][..payload_len],
&buffer[*frag_offset as usize + repr.buffer_len()..][..payload_len],
);

// Update the frag offset for the next fragment.
Expand Down
4 changes: 2 additions & 2 deletions src/socket/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl Default for RttEstimator {
impl RttEstimator {
fn retransmission_timeout(&self) -> Duration {
let margin = RTTE_MIN_MARGIN.max(self.deviation * 4);
let ms = (self.rtt + margin).max(RTTE_MIN_RTO).min(RTTE_MAX_RTO);
let ms = (self.rtt + margin).clamp(RTTE_MIN_RTO, RTTE_MAX_RTO);
Duration::from_millis(ms as u64)
}

Expand Down Expand Up @@ -1442,7 +1442,7 @@ impl<'a> Socket<'a> {

if segment_in_window {
// We've checked that segment_start >= window_start above.
payload_offset = (segment_start - window_start) as usize;
payload_offset = segment_start - window_start;
self.local_rx_last_seq = Some(repr.seq_number);
} else {
// If we're in the TIME-WAIT state, restart the TIME-WAIT timeout, since
Expand Down
2 changes: 1 addition & 1 deletion src/wire/icmpv6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ impl<'a> Repr<'a> {
{
let ip_packet = Ipv6Packet::new_checked(packet.payload())?;

let payload = &packet.payload()[ip_packet.header_len() as usize..];
let payload = &packet.payload()[ip_packet.header_len()..];
if payload.len() < 8 {
return Err(Error);
}
Expand Down
2 changes: 1 addition & 1 deletion src/wire/igmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl<T: AsRef<[u8]>> Packet<T> {
/// Returns `Err(Error)` if the buffer is too short.
pub fn check_len(&self) -> Result<()> {
let len = self.buffer.as_ref().len();
if len < field::GROUP_ADDRESS.end as usize {
if len < field::GROUP_ADDRESS.end {
Err(Error)
} else {
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions src/wire/ipv6hopbyhop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,14 @@ mod test {
#[test]
fn test_header_len_overflow() {
let mut bytes = vec![];
bytes.extend(&REPR_PACKET_PAD4);
bytes.extend(REPR_PACKET_PAD4);
let len = bytes.len() as u8;
Header::new_unchecked(&mut bytes).set_header_len(len + 1);

assert_eq!(Header::new_checked(&bytes).unwrap_err(), Error);

let mut bytes = vec![];
bytes.extend(&REPR_PACKET_PAD12);
bytes.extend(REPR_PACKET_PAD12);
let len = bytes.len() as u8;
Header::new_unchecked(&mut bytes).set_header_len(len + 1);

Expand Down
2 changes: 1 addition & 1 deletion src/wire/ipv6routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl<T: AsRef<[u8]>> Header<T> {
return Err(Error);
}

if len < field::DATA(self.header_len()).end as usize {
if len < field::DATA(self.header_len()).end {
return Err(Error);
}

Expand Down
15 changes: 7 additions & 8 deletions src/wire/sixlowpan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1215,10 +1215,9 @@ pub mod iphc {
let mut len = 0;
len += 2; // The minimal header length

len += if self.next_header == NextHeader::Compressed {
0 // The next header is compressed (we don't need to inline what the next header is)
} else {
1 // The next header field is inlined
len += match self.next_header {
NextHeader::Compressed => 0, // The next header is compressed (we don't need to inline what the next header is)
NextHeader::Uncompressed(_) => 1, // The next header field is inlined
};

// Hop Limit size
Expand Down Expand Up @@ -1604,10 +1603,10 @@ pub mod nhc {
/// Return the size of the Next Header field.
fn next_header_size(&self) -> usize {
// If nh is set, then the Next Header is compressed using LOWPAN_NHC
if self.nh_field() == 1 {
0
} else {
1
match self.nh_field() {
0 => 1,
1 => 0,
_ => unreachable!(),
}
}
}
Expand Down

0 comments on commit b92fc8f

Please sign in to comment.