Skip to content

Commit

Permalink
Resolved cippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianSchmid committed May 7, 2023
1 parent 69ae3ad commit c33f1b8
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 16 deletions.
5 changes: 1 addition & 4 deletions etherparse/src/err/packet/build_write_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ impl BuildWriteError {

/// Returns true if the `BuildWriteError` is a `Icmpv6InIpv4`.
pub fn is_icmpv6_in_ipv4(&self) -> bool {
match self {
BuildWriteError::Icmpv6InIpv4 => true,
_ => false,
}
matches!(self, BuildWriteError::Icmpv6InIpv4)
}
}

Expand Down
8 changes: 3 additions & 5 deletions etherparse/src/internet/ip_number_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,12 +737,10 @@ impl core::fmt::Debug for IpNumber {
} else {
write!(f, "{} ({})", self.0, keyword)
}
} else if let Some(protocol) = self.protocol_str() {
write!(f, "{} ({})", self.0, protocol)
} else {
if let Some(protocol) = self.protocol_str() {
write!(f, "{} ({})", self.0, protocol)
} else {
write!(f, "{}", self.0)
}
write!(f, "{}", self.0)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion etherparse/src/internet/ipv4_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ impl Ipv4Header {
options: {
let mut options = Ipv4Options::new();
options.len = (ihl - 5) * 4;
if options.len() > 0 {
if false == options.is_empty() {
reader.read_exact(options.as_mut()).map_err(Io)?;
}
options
Expand Down
18 changes: 18 additions & 0 deletions etherparse/src/internet/ipv4_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ impl Ipv4Options {
pub fn len(&self) -> u8 {
self.len
}

/// Returns if the length of the options is zero.
#[inline]
pub fn is_empty(&self) -> bool {
self.len == 0
}
}

impl TryFrom<&[u8]> for Ipv4Options {
Expand Down Expand Up @@ -253,6 +259,18 @@ mod tests {
assert_eq!(actual.buf, [0; 40]);
}

#[test]
fn is_empty() {
{
let actual = Ipv4Options::new();
assert!(actual.is_empty());
}
{
let actual: Ipv4Options = [1, 2, 3, 4].into();
assert_eq!(false, actual.is_empty());
}
}

#[test]
fn try_from() {
const DATA: [u8; 48] = [
Expand Down
2 changes: 1 addition & 1 deletion etherparse/src/internet/ipv6_flow_label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Ipv6FlowLabel {
pub const ZERO: Ipv6FlowLabel = Ipv6FlowLabel(0);

/// Maximum value of an IPv6 Flow Label.
pub const MAX_U32: u32 = 0b1111_11111111_11111111;
pub const MAX_U32: u32 = 0b1111_1111_1111_1111_1111;

/// Tries to create an [`Ipv6FlowLabel`] and checks that the passed value
/// is smaller or equal than [`Ipv6FlowLabel::MAX_U32`] (20 bit unsigned integer).
Expand Down
2 changes: 1 addition & 1 deletion etherparse/src/internet/ipv6_fragment_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl Ipv6FragmentHeader {
/// Writes a given IPv6 fragment header to the current position.
#[cfg(feature = "std")]
pub fn write<T: std::io::Write + Sized>(&self, writer: &mut T) -> Result<(), std::io::Error> {
Ok(writer.write_all(&self.to_bytes())?)
writer.write_all(&self.to_bytes())
}

/// Length of the header in bytes.
Expand Down
2 changes: 1 addition & 1 deletion etherparse/src/internet/ipv6_raw_ext_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl Ipv6RawExtHeader {
#[cfg(test)]
mod test {
use super::*;
use crate::{test_gens::*, *};
use crate::test_gens::*;
use alloc::{format, vec::Vec};
use proptest::prelude::*;
use std::io::Cursor;
Expand Down
4 changes: 2 additions & 2 deletions etherparse/src/transport/tcp_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ impl TcpHeader {
.add_4bytes(source_ip)
.add_4bytes(destination_ip)
.add_2bytes([0, ip_number::TCP.0])
.add_2bytes((tcp_len as u16).to_be_bytes()),
.add_2bytes(tcp_len.to_be_bytes()),
payload,
))
}
Expand Down Expand Up @@ -606,7 +606,7 @@ impl TcpHeader {
checksum::Sum16BitWords::new()
.add_16bytes(source)
.add_16bytes(destination)
.add_4bytes((tcp_len as u32).to_be_bytes())
.add_4bytes(tcp_len.to_be_bytes())
.add_2bytes([0, ip_number::TCP.0]),
payload,
))
Expand Down
2 changes: 1 addition & 1 deletion etherparse_proptest_generators/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ prop_compose! {

prop_compose! {
pub fn ipv6_flow_label_any()
(value in 0u32..=0b1111_11111111_11111111u32)
(value in 0u32..=0b1111_1111_1111_1111_1111_u32)
-> Ipv6FlowLabel
{
Ipv6FlowLabel::try_new(value).unwrap()
Expand Down

0 comments on commit c33f1b8

Please sign in to comment.