Skip to content

Commit 7480a2a

Browse files
eval-execzhangsoledad
authored andcommitted
ckb-network-fuzz: make cargo clippy happy
Signed-off-by: Eval EXEC <[email protected]>
1 parent 0c33ad8 commit 7480a2a

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

network/fuzz/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ cargo-fuzz = true
1313

1414
[dependencies]
1515
libfuzzer-sys = "0.4"
16-
ipnetwork = "0.18"
16+
ipnetwork = "0.20.0"
1717

1818
[dependencies.ckb-network]
1919
path = ".."

network/fuzz/fuzz_targets/fuzz_addr_manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn new_addr(data: &[u8], index: usize) -> AddrInfo {
2020
// let ip = Ipv4Addr::from(((225 << 24) + index) as u32);
2121
// let port = u16::from_le_bytes(data[4..6].try_into().unwrap());
2222
let peer_id =
23-
PeerId::from_bytes(vec![vec![0x12], vec![0x20], data[4..].to_vec()].concat()).unwrap();
23+
PeerId::from_bytes([vec![0x12], vec![0x20], data[4..].to_vec()].concat()).unwrap();
2424

2525
AddrInfo::new(
2626
format!("/ip4/{}/tcp/43/p2p/{}", ip, peer_id.to_base58())

network/fuzz/fuzz_targets/fuzz_peer_store.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ fn new_multi_addr(data: &mut BufManager) -> (MultiAddr, Flags) {
1515
let buf = data.get_buf(16);
1616
format!(
1717
"/ip6/{}",
18-
std::net::Ipv6Addr::from(u128::from_le_bytes(buf.try_into().unwrap())).to_string()
18+
std::net::Ipv6Addr::from(u128::from_le_bytes(buf.try_into().unwrap()))
1919
)
2020
} else {
21-
format!("/ip4/{}", data.get::<std::net::Ipv4Addr>().to_string())
21+
format!("/ip4/{}", data.get::<std::net::Ipv4Addr>())
2222
};
2323

2424
addr_str += &format!("/tcp/{}", data.get::<u16>());
@@ -66,7 +66,7 @@ fn add_basic_addr(data: &mut BufManager, peer_store: &mut PeerStore) {
6666
for i in 0..num {
6767
let addr = format!(
6868
"/ip4/{}/tcp/43/p2p/{}",
69-
std::net::Ipv4Addr::from(i as u32).to_string(),
69+
std::net::Ipv4Addr::from(i),
7070
PeerId::random().to_base58()
7171
)
7272
.parse()

network/fuzz/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ impl<'a> BufManager<'a> {
1414
}
1515
}
1616

17+
pub fn is_empty(&self) -> bool {
18+
self.buf.is_empty()
19+
}
20+
1721
pub fn len(&self) -> usize {
1822
self.buf.len()
1923
}
@@ -25,8 +29,7 @@ impl<'a> BufManager<'a> {
2529
self.offset += len;
2630
r
2731
} else {
28-
let mut r = Vec::<u8>::with_capacity(len);
29-
r.resize(len, 0);
32+
let mut r = vec![0; len];
3033
r[0..(buf_len - self.offset)].copy_from_slice(&self.buf[self.offset..]);
3134
self.offset = buf_len;
3235
r
@@ -138,6 +141,6 @@ impl FromBytes<PeerId> for PeerId {
138141
32
139142
}
140143
fn from_bytes(d: &[u8]) -> PeerId {
141-
PeerId::from_bytes(vec![vec![0x12], vec![0x20], d.to_vec()].concat()).unwrap()
144+
PeerId::from_bytes([vec![0x12], vec![0x20], d.to_vec()].concat()).unwrap()
142145
}
143146
}

0 commit comments

Comments
 (0)