bpf_loader: fix clippy::blocks_in_conditions lint (#34643)

See https://github.com/solana-labs/solana/issues/34626
This commit is contained in:
Alessandro Decina 2024-01-04 11:58:10 +11:00 committed by GitHub
parent 0b49d82d3e
commit 917e242e7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 15 deletions

View File

@ -216,6 +216,21 @@ fn memcmp_non_contiguous(
n: u64,
memory_mapping: &MemoryMapping,
) -> Result<i32, Error> {
let memcmp_chunk = |s1_addr, s2_addr, chunk_len| {
let res = unsafe {
let s1 = slice::from_raw_parts(s1_addr, chunk_len);
let s2 = slice::from_raw_parts(s2_addr, chunk_len);
// Safety:
// memcmp is marked unsafe since it assumes that s1 and s2 are exactly chunk_len
// long. The whole point of iter_memory_pair_chunks is to find same length chunks
// across two memory regions.
memcmp(s1, s2, chunk_len)
};
if res != 0 {
return Err(MemcmpError::Diff(res).into());
}
Ok(0)
};
match iter_memory_pair_chunks(
AccessType::Load,
src_addr,
@ -224,21 +239,7 @@ fn memcmp_non_contiguous(
n,
memory_mapping,
false,
|s1_addr, s2_addr, chunk_len| {
let res = unsafe {
let s1 = slice::from_raw_parts(s1_addr, chunk_len);
let s2 = slice::from_raw_parts(s2_addr, chunk_len);
// Safety:
// memcmp is marked unsafe since it assumes that s1 and s2 are exactly chunk_len
// long. The whole point of iter_memory_pair_chunks is to find same length chunks
// across two memory regions.
memcmp(s1, s2, chunk_len)
};
if res != 0 {
return Err(MemcmpError::Diff(res).into());
}
Ok(0)
},
memcmp_chunk,
) {
Ok(res) => Ok(res),
Err(error) => match error.downcast_ref() {