Skip to content

Commit

Permalink
Remove unnecessary casts.
Browse files Browse the repository at this point in the history
  • Loading branch information
StygianLightning authored and Ralith committed Dec 10, 2022
1 parent 943b78c commit 389d7ce
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 25 deletions.
2 changes: 1 addition & 1 deletion quinn-proto/src/congestion/cubic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl Controller for Cubic {
// cwnd_inc can be more than 1 MSS in the late stage of max probing.
// however RFC9002 §7.3.3 (Congestion Avoidance) limits
// the increase of cwnd to 1 max_datagram_size per cwnd acknowledged.
if self.cubic_state.cwnd_inc as u64 >= self.config.max_datagram_size {
if self.cubic_state.cwnd_inc >= self.config.max_datagram_size {
self.window += self.config.max_datagram_size;
self.cubic_state.cwnd_inc = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ impl Connection {
let largest_lost_sent = self.spaces[pn_space].sent_packets[&largest_lost].time_sent;
self.lost_packets += lost_packets.len() as u64;
self.stats.path.lost_packets += lost_packets.len() as u64;
self.stats.path.lost_bytes += size_of_lost_packets as u64;
self.stats.path.lost_bytes += size_of_lost_packets;
trace!(
"packets lost: {:?}, bytes lost: {}",
lost_packets,
Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/connection/streams/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl StreamsState {
self.max[Dir::Uni as usize] = params.initial_max_streams_uni.into();
self.received_max_data(params.initial_max_data);
for i in 0..self.max_remote[Dir::Bi as usize] {
let id = StreamId::new(!self.side, Dir::Bi, i as u64);
let id = StreamId::new(!self.side, Dir::Bi, i);
self.send.get_mut(&id).unwrap().max_data =
params.initial_max_stream_data_bidi_local.into();
}
Expand Down
9 changes: 1 addition & 8 deletions quinn-proto/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,14 +598,7 @@ impl Endpoint {
if dst_cid.len() != 0 {
self.connection_ids_initial.insert(dst_cid, ch);
}
match conn.handle_first_packet(
now,
addresses.remote,
ecn,
packet_number as u64,
packet,
rest,
) {
match conn.handle_first_packet(now, addresses.remote, ecn, packet_number, packet, rest) {
Ok(()) => {
trace!(id = ch.0, icid = %dst_cid, "connection incoming");
Some((ch, conn))
Expand Down
3 changes: 1 addition & 2 deletions quinn-proto/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,7 @@ impl ApplicationClose {
pub(crate) fn encode<W: BufMut>(&self, out: &mut W, max_len: usize) {
out.write(Type::APPLICATION_CLOSE); // 1 byte
out.write(self.error_code); // <= 8 bytes
let max_len =
max_len as usize - 3 - VarInt::from_u64(self.reason.len() as u64).unwrap().size();
let max_len = max_len - 3 - VarInt::from_u64(self.reason.len() as u64).unwrap().size();
let actual_len = self.reason.len().min(max_len);
out.write_var(actual_len as u64); // <= 8 bytes
out.put_slice(&self.reason[0..actual_len]); // whatever's left
Expand Down
3 changes: 1 addition & 2 deletions quinn-proto/src/transport_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,7 @@ impl TransportParameters {
if params.preferred_address.is_some() {
return Err(Error::Malformed);
}
params.preferred_address =
Some(PreferredAddress::read(&mut r.take(len as usize))?);
params.preferred_address = Some(PreferredAddress::read(&mut r.take(len))?);
}
0x0f => decode_cid(len, &mut params.initial_src_cid, r)?,
0x10 => decode_cid(len, &mut params.retry_src_cid, r)?,
Expand Down
26 changes: 16 additions & 10 deletions quinn-udp/src/cmsg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ impl<'a> Encoder<'a> {
pub fn push<T: Copy + ?Sized>(&mut self, level: libc::c_int, ty: libc::c_int, value: T) {
assert!(mem::align_of::<T>() <= mem::align_of::<libc::cmsghdr>());
let space = unsafe { libc::CMSG_SPACE(mem::size_of_val(&value) as _) as usize };
assert!(
self.hdr.msg_controllen as usize >= self.len + space,
"control message buffer too small. Required: {}, Available: {}",
self.len + space,
self.hdr.msg_controllen
);
#[allow(clippy::unnecessary_cast)] // hdr.msg_controllen defined as size_t
{
assert!(
self.hdr.msg_controllen as usize >= self.len + space,
"control message buffer too small. Required: {}, Available: {}",
self.len + space,
self.hdr.msg_controllen
);
}
let cmsg = self.cmsg.take().expect("no control buffer space remaining");
cmsg.cmsg_level = level;
cmsg.cmsg_type = ty;
Expand Down Expand Up @@ -71,10 +74,13 @@ impl<'a> Drop for Encoder<'a> {
/// `cmsg` must refer to a cmsg containing a payload of type `T`
pub unsafe fn decode<T: Copy>(cmsg: &libc::cmsghdr) -> T {
assert!(mem::align_of::<T>() <= mem::align_of::<libc::cmsghdr>());
debug_assert_eq!(
cmsg.cmsg_len as usize,
libc::CMSG_LEN(mem::size_of::<T>() as _) as usize
);
#[allow(clippy::unnecessary_cast)] // cmsg.cmsg_len defined as size_t
{
debug_assert_eq!(
cmsg.cmsg_len as usize,
libc::CMSG_LEN(mem::size_of::<T>() as _) as usize
);
}
ptr::read(libc::CMSG_DATA(cmsg) as *const T)
}

Expand Down
1 change: 1 addition & 0 deletions quinn-udp/src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ fn decode_recv(
(libc::IPPROTO_IPV6, libc::IPV6_TCLASS) => unsafe {
// Temporary hack around broken macos ABI. Remove once upstream fixes it.
// https://bugreport.apple.com/web/?problemID=48761855
#[allow(clippy::unnecessary_cast)] // cmsg.cmsg_len defined as size_t
if cfg!(target_os = "macos")
&& cmsg.cmsg_len as usize == libc::CMSG_LEN(mem::size_of::<u8>() as _) as usize
{
Expand Down

0 comments on commit 389d7ce

Please sign in to comment.