From e7ba639a3910a42608e05ae982fba9b5463b8ba0 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 3 Jan 2025 16:20:15 +0800 Subject: [PATCH] ckb-network-fuzz: make cargo clippy happy Signed-off-by: Eval EXEC --- network/fuzz/Cargo.toml | 2 +- network/fuzz/fuzz_targets/fuzz_addr_manager.rs | 2 +- network/fuzz/src/lib.rs | 9 ++++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/network/fuzz/Cargo.toml b/network/fuzz/Cargo.toml index c04cc377627..f4eb181c015 100644 --- a/network/fuzz/Cargo.toml +++ b/network/fuzz/Cargo.toml @@ -13,7 +13,7 @@ cargo-fuzz = true [dependencies] libfuzzer-sys = "0.4" -ipnetwork = "0.18" +ipnetwork = "0.20.0" [dependencies.ckb-network] path = ".." diff --git a/network/fuzz/fuzz_targets/fuzz_addr_manager.rs b/network/fuzz/fuzz_targets/fuzz_addr_manager.rs index f4665c05122..d788ae9bfae 100644 --- a/network/fuzz/fuzz_targets/fuzz_addr_manager.rs +++ b/network/fuzz/fuzz_targets/fuzz_addr_manager.rs @@ -20,7 +20,7 @@ fn new_addr(data: &[u8], index: usize) -> AddrInfo { // let ip = Ipv4Addr::from(((225 << 24) + index) as u32); // let port = u16::from_le_bytes(data[4..6].try_into().unwrap()); let peer_id = - PeerId::from_bytes(vec![vec![0x12], vec![0x20], data[4..].to_vec()].concat()).unwrap(); + PeerId::from_bytes([vec![0x12], vec![0x20], data[4..].to_vec()].concat()).unwrap(); AddrInfo::new( format!("/ip4/{}/tcp/43/p2p/{}", ip, peer_id.to_base58()) diff --git a/network/fuzz/src/lib.rs b/network/fuzz/src/lib.rs index 94138a6b277..32e680c541c 100644 --- a/network/fuzz/src/lib.rs +++ b/network/fuzz/src/lib.rs @@ -14,6 +14,10 @@ impl<'a> BufManager<'a> { } } + pub fn is_empty(&self) -> bool { + self.buf.is_empty() + } + pub fn len(&self) -> usize { self.buf.len() } @@ -25,8 +29,7 @@ impl<'a> BufManager<'a> { self.offset += len; r } else { - let mut r = Vec::::with_capacity(len); - r.resize(len, 0); + let mut r = vec![0; len]; r[0..(buf_len - self.offset)].copy_from_slice(&self.buf[self.offset..]); self.offset = buf_len; r @@ -138,6 +141,6 @@ impl FromBytes for PeerId { 32 } fn from_bytes(d: &[u8]) -> PeerId { - PeerId::from_bytes(vec![vec![0x12], vec![0x20], d.to_vec()].concat()).unwrap() + PeerId::from_bytes([vec![0x12], vec![0x20], d.to_vec()].concat()).unwrap() } }