Skip to content

Commit

Permalink
ckb-network-fuzz: make cargo clippy happy
Browse files Browse the repository at this point in the history
Signed-off-by: Eval EXEC <[email protected]>
  • Loading branch information
eval-exec committed Jan 3, 2025
1 parent b8cb85c commit e7ba639
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion network/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"
ipnetwork = "0.18"
ipnetwork = "0.20.0"

[dependencies.ckb-network]
path = ".."
Expand Down
2 changes: 1 addition & 1 deletion network/fuzz/fuzz_targets/fuzz_addr_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
9 changes: 6 additions & 3 deletions network/fuzz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -25,8 +29,7 @@ impl<'a> BufManager<'a> {
self.offset += len;
r
} else {
let mut r = Vec::<u8>::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
Expand Down Expand Up @@ -138,6 +141,6 @@ impl FromBytes<PeerId> 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()
}
}

0 comments on commit e7ba639

Please sign in to comment.