Skip to content

Commit

Permalink
making code more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
riesentoaster committed Nov 26, 2024
1 parent 6cf8092 commit f9814a6
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions libafl_bolts/src/shmem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,13 +701,12 @@ pub mod unix_shmem {
// FFI Calls.
unsafe {
let mut filename_path: [u8; 20] = [0_u8; MAX_MMAP_FILENAME_LEN];
// Determine the number of elements to copy
// Keep room for the leading slash and trailing NULL.
let max_copy = usize::min(filename.len(), MAX_MMAP_FILENAME_LEN - 2);

// Perform the copy using slice indexing and `copy_from_slice`
filename_path[1..1 + max_copy].copy_from_slice(&filename[..max_copy]);
filename_path[0] = b'/';
filename_path[MAX_MMAP_FILENAME_LEN - 1] = 0; // Null terminate!
filename_path[MAX_MMAP_FILENAME_LEN - 1] = 0;
filename_path[1..=max_copy].copy_from_slice(&filename[..max_copy]);

log::info!(
"{} Creating shmem {} {:#?}",
map_size,
Expand Down

0 comments on commit f9814a6

Please sign in to comment.