replaced next_pow2 with proper rust
This commit is contained in:
parent
568f028314
commit
d91e516bb2
@ -67,7 +67,6 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use super::shmem::{ShMem, ShMemDescription};
|
use super::shmem::{ShMem, ShMemDescription};
|
||||||
use crate::utils::next_pow2;
|
|
||||||
use crate::AflError;
|
use crate::AflError;
|
||||||
|
|
||||||
/// We'll start off with 256 megabyte maps per fuzzer client
|
/// We'll start off with 256 megabyte maps per fuzzer client
|
||||||
@ -155,10 +154,11 @@ fn msg_offset_from_env(env_name: &str) -> Result<Option<u64>, AflError> {
|
|||||||
/// largest messages we encountered (plus message one new_page message).
|
/// largest messages we encountered (plus message one new_page message).
|
||||||
#[inline]
|
#[inline]
|
||||||
fn new_map_size(max_alloc: usize) -> usize {
|
fn new_map_size(max_alloc: usize) -> usize {
|
||||||
next_pow2(max(
|
max(
|
||||||
max_alloc * 2 + EOP_MSG_SIZE + LLMP_PAGE_HEADER_LEN,
|
max_alloc * 2 + EOP_MSG_SIZE + LLMP_PAGE_HEADER_LEN,
|
||||||
LLMP_PREF_INITIAL_MAP_SIZE,
|
LLMP_PREF_INITIAL_MAP_SIZE,
|
||||||
) as u64) as usize
|
)
|
||||||
|
.next_power_of_two()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Initialize a new llmp_page. size should be relative to
|
/// Initialize a new llmp_page. size should be relative to
|
||||||
|
@ -59,7 +59,7 @@ impl BytesInput {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::utils::{next_pow2, Rand, StdRand};
|
use crate::utils::{Rand, StdRand};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_input() {
|
fn test_input() {
|
||||||
@ -70,13 +70,4 @@ mod tests {
|
|||||||
assert_eq!(rand.between(10, 10), 10);
|
assert_eq!(rand.between(10, 10), 10);
|
||||||
assert!(rand.between(11, 20) > 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
//use xxhash_rust::xxh3::xxh3_64_with_seed;
|
//use xxhash_rust::xxh3::xxh3_64_with_seed;
|
||||||
|
|
||||||
use crate::utils::{next_pow2, Rand, StdRand};
|
use crate::utils::{Rand, StdRand};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rand() {
|
fn test_rand() {
|
||||||
@ -481,14 +469,4 @@ mod tests {
|
|||||||
assert_eq!(rand.between(10, 10), 10);
|
assert_eq!(rand.between(10, 10), 10);
|
||||||
assert!(rand.between(11, 20) > 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user