diff --git a/afl/src/events/llmp.rs b/afl/src/events/llmp.rs index 43446acec1..ab470390e2 100644 --- a/afl/src/events/llmp.rs +++ b/afl/src/events/llmp.rs @@ -67,7 +67,6 @@ use std::{ }; use super::shmem::{ShMem, ShMemDescription}; -use crate::utils::next_pow2; use crate::AflError; /// We'll start off with 256 megabyte maps per fuzzer client @@ -155,10 +154,11 @@ fn msg_offset_from_env(env_name: &str) -> Result, AflError> { /// largest messages we encountered (plus message one new_page message). #[inline] fn new_map_size(max_alloc: usize) -> usize { - next_pow2(max( + max( max_alloc * 2 + EOP_MSG_SIZE + LLMP_PAGE_HEADER_LEN, LLMP_PREF_INITIAL_MAP_SIZE, - ) as u64) as usize + ) + .next_power_of_two() } /// Initialize a new llmp_page. size should be relative to diff --git a/afl/src/inputs/bytes.rs b/afl/src/inputs/bytes.rs index f2e5d8829e..308ff26e59 100644 --- a/afl/src/inputs/bytes.rs +++ b/afl/src/inputs/bytes.rs @@ -59,7 +59,7 @@ impl BytesInput { #[cfg(test)] mod tests { - use crate::utils::{next_pow2, Rand, StdRand}; + use crate::utils::{Rand, StdRand}; #[test] fn test_input() { @@ -70,13 +70,4 @@ mod tests { assert_eq!(rand.between(10, 10), 10); assert!(rand.between(11, 20) > 10); } - - #[test] - fn test_next_pow2() { - assert_eq!(next_pow2(0), 0); - assert_eq!(next_pow2(1), 1); - assert_eq!(next_pow2(2), 2); - assert_eq!(next_pow2(3), 4); - assert_eq!(next_pow2(1000), 1024); - } } diff --git a/afl/src/utils.rs b/afl/src/utils.rs index 8b38da47a7..bcba188d07 100644 --- a/afl/src/utils.rs +++ b/afl/src/utils.rs @@ -441,23 +441,11 @@ impl XKCDRand { } } -/// Get the next higher power of two -#[inline] -pub const fn next_pow2(val: u64) -> u64 { - let mut out = val.wrapping_sub(1); - out |= out >> 1; - out |= out >> 2; - out |= out >> 4; - out |= out >> 8; - out |= out >> 16; - out.wrapping_add(1) -} - #[cfg(test)] mod tests { //use xxhash_rust::xxh3::xxh3_64_with_seed; - use crate::utils::{next_pow2, Rand, StdRand}; + use crate::utils::{Rand, StdRand}; #[test] fn test_rand() { @@ -481,14 +469,4 @@ mod tests { assert_eq!(rand.between(10, 10), 10); assert!(rand.between(11, 20) > 10); } - - #[test] - fn test_next_pow2() { - assert_eq!(next_pow2(0), 0); - assert_eq!(next_pow2(1), 1); - assert_eq!(next_pow2(2), 2); - assert_eq!(next_pow2(3), 4); - assert_eq!(next_pow2(1000), 1024); - assert_eq!(next_pow2(0xFFFFFFFF as u64), (0xFFFFFFFF as u64) + 1); - } }