replaced next_pow2 with proper rust

This commit is contained in:
Dominik Maier 2021-02-02 03:13:46 +01:00
parent 568f028314
commit d91e516bb2
3 changed files with 5 additions and 36 deletions

View File

@ -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<Option<u64>, 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

View File

@ -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);
}
}

View File

@ -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);
}
}