Use SHMEM_FUZZ_HDR_SIZE constant (#695)

* Fix misuse of SHMEM_FUZZ_HDR_SIZE

* fix `cargo fmt`

Co-authored-by: syheliel <syheliel@gmail.com>
This commit is contained in:
syheliel 2022-07-08 15:45:56 +08:00 committed by GitHub
parent 7870a6e699
commit 253c6b5bdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,6 +44,7 @@ const FS_OPT_ENABLED: i32 = 0x80000001_u32 as i32;
const FS_OPT_SHDMEM_FUZZ: i32 = 0x01000000_u32 as i32; const FS_OPT_SHDMEM_FUZZ: i32 = 0x01000000_u32 as i32;
#[allow(clippy::cast_possible_wrap)] #[allow(clippy::cast_possible_wrap)]
const FS_OPT_AUTODICT: i32 = 0x10000000_u32 as i32; const FS_OPT_AUTODICT: i32 = 0x10000000_u32 as i32;
/// The length of header bytes which tells shmem size
const SHMEM_FUZZ_HDR_SIZE: usize = 4; const SHMEM_FUZZ_HDR_SIZE: usize = 4;
const MAX_FILE: usize = 1024 * 1024; const MAX_FILE: usize = 1024 * 1024;
@ -870,7 +871,8 @@ where
let size = target_bytes.as_slice().len(); let size = target_bytes.as_slice().len();
let size_in_bytes = size.to_ne_bytes(); let size_in_bytes = size.to_ne_bytes();
// The first four bytes tells the size of the shmem. // The first four bytes tells the size of the shmem.
map.as_mut_slice()[..4].copy_from_slice(&size_in_bytes[..4]); map.as_mut_slice()[..SHMEM_FUZZ_HDR_SIZE]
.copy_from_slice(&size_in_bytes[..SHMEM_FUZZ_HDR_SIZE]);
map.as_mut_slice()[SHMEM_FUZZ_HDR_SIZE..(SHMEM_FUZZ_HDR_SIZE + size)] map.as_mut_slice()[SHMEM_FUZZ_HDR_SIZE..(SHMEM_FUZZ_HDR_SIZE + size)]
.copy_from_slice(target_bytes.as_slice()); .copy_from_slice(target_bytes.as_slice());
} }