Use const_assert not assert (#1949)

* stuff

* FMT
This commit is contained in:
Dongjia "toka" Zhang 2024-03-16 03:33:20 +01:00 committed by GitHub
parent c6420c0987
commit 44a37da680
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 24 additions and 8 deletions

View File

@ -300,7 +300,10 @@ where
/// Gets the next entry at random /// Gets the next entry at random
fn next(&mut self, state: &mut Self::State) -> Result<CorpusId, Error> { fn next(&mut self, state: &mut Self::State) -> Result<CorpusId, Error> {
if state.corpus().count() == 0 { if state.corpus().count() == 0 {
Err(Error::empty("No entries in corpus. This often implies the target is not properly instrumented.".to_owned())) Err(Error::empty(
"No entries in corpus. This often implies the target is not properly instrumented."
.to_owned(),
))
} else { } else {
let id = random_corpus_id!(state.corpus(), state.rand_mut()); let id = random_corpus_id!(state.corpus(), state.rand_mut());
self.set_current_scheduled(state, Some(id))?; self.set_current_scheduled(state, Some(id))?;

View File

@ -259,7 +259,9 @@ where
fn next(&mut self, state: &mut Self::State) -> Result<CorpusId, Error> { fn next(&mut self, state: &mut Self::State) -> Result<CorpusId, Error> {
if state.corpus().count() == 0 { if state.corpus().count() == 0 {
Err(Error::empty(String::from("No entries in corpus. This often implies the target is not properly instrumented."))) Err(Error::empty(String::from(
"No entries in corpus. This often implies the target is not properly instrumented.",
)))
} else { } else {
let id = match state.corpus().current() { let id = match state.corpus().current() {
Some(cur) => { Some(cur) => {

View File

@ -158,7 +158,9 @@ where
#[allow(clippy::cast_precision_loss)] #[allow(clippy::cast_precision_loss)]
fn next(&mut self, state: &mut Self::State) -> Result<CorpusId, Error> { fn next(&mut self, state: &mut Self::State) -> Result<CorpusId, Error> {
if state.corpus().count() == 0 { if state.corpus().count() == 0 {
Err(Error::empty(String::from("No entries in corpus. This often implies the target is not properly instrumented."))) Err(Error::empty(String::from(
"No entries in corpus. This often implies the target is not properly instrumented.",
)))
} else { } else {
let rand_prob: f64 = (state.rand_mut().below(100) as f64) / 100.0; let rand_prob: f64 = (state.rand_mut().below(100) as f64) / 100.0;
let meta = state.metadata_map().get::<ProbabilityMetadata>().unwrap(); let meta = state.metadata_map().get::<ProbabilityMetadata>().unwrap();

View File

@ -44,7 +44,10 @@ where
/// Gets the next entry in the queue /// Gets the next entry in the queue
fn next(&mut self, state: &mut Self::State) -> Result<CorpusId, Error> { fn next(&mut self, state: &mut Self::State) -> Result<CorpusId, Error> {
if state.corpus().count() == 0 { if state.corpus().count() == 0 {
Err(Error::empty("No entries in corpus. This often implies the target is not properly instrumented.".to_owned())) Err(Error::empty(
"No entries in corpus. This often implies the target is not properly instrumented."
.to_owned(),
))
} else { } else {
let id = state let id = state
.corpus() .corpus()

View File

@ -119,7 +119,10 @@ where
/// Gets the next entry in the queue /// Gets the next entry in the queue
fn next(&mut self, state: &mut Self::State) -> Result<CorpusId, Error> { fn next(&mut self, state: &mut Self::State) -> Result<CorpusId, Error> {
if state.corpus().count() == 0 { if state.corpus().count() == 0 {
return Err(Error::empty("No entries in corpus. This often implies the target is not properly instrumented.".to_owned())); return Err(Error::empty(
"No entries in corpus. This often implies the target is not properly instrumented."
.to_owned(),
));
} }
let id = if let Some(next) = Self::get_next(state) { let id = if let Some(next) = Self::get_next(state) {
// next was set // next was set

View File

@ -303,7 +303,9 @@ where
fn next(&mut self, state: &mut S) -> Result<CorpusId, Error> { fn next(&mut self, state: &mut S) -> Result<CorpusId, Error> {
let corpus_counts = state.corpus().count(); let corpus_counts = state.corpus().count();
if corpus_counts == 0 { if corpus_counts == 0 {
Err(Error::empty(String::from("No entries in corpus. This often implies the target is not properly instrumented."))) Err(Error::empty(String::from(
"No entries in corpus. This often implies the target is not properly instrumented.",
)))
} else { } else {
let s = random_corpus_id!(state.corpus(), state.rand_mut()); let s = random_corpus_id!(state.corpus(), state.rand_mut());

View File

@ -86,6 +86,7 @@ rustversion = "1.0"
[dependencies] [dependencies]
libafl_derive = { version = "0.11.2", optional = true, path = "../libafl_derive" } libafl_derive = { version = "0.11.2", optional = true, path = "../libafl_derive" }
static_assertions = "1.1.0"
rustversion = "1.0" rustversion = "1.0"
tuple_list = { version = "0.1.3" } tuple_list = { version = "0.1.3" }

View File

@ -49,7 +49,7 @@ macro_rules! impl_asany {
#[must_use] #[must_use]
pub const fn pack_type_id(id: u128) -> TypeId { pub const fn pack_type_id(id: u128) -> TypeId {
// TypeId size of other sizes is not yet supported" // TypeId size of other sizes is not yet supported"
assert!(size_of::<TypeId>() == 16, "Unsupported size for TypeId"); static_assertions::const_assert!(size_of::<TypeId>() == 16);
unsafe { *(addr_of!(id) as *const TypeId) } unsafe { *(addr_of!(id) as *const TypeId) }
} }
@ -64,7 +64,7 @@ pub const fn pack_type_id(id: u128) -> TypeId {
pub const fn unpack_type_id(id: TypeId) -> u128 { pub const fn unpack_type_id(id: TypeId) -> u128 {
// see any.rs, it's alway u128 hence 16 bytes. // see any.rs, it's alway u128 hence 16 bytes.
// TypeId size of other sizes is not yet supported" // TypeId size of other sizes is not yet supported"
assert!(size_of::<TypeId>() == 16, "Unsupported size for TypeId"); static_assertions::const_assert!(size_of::<TypeId>() == 16);
let ret: u128 = unsafe { read_unaligned::<u128>(addr_of!(id) as *const u128) }; let ret: u128 = unsafe { read_unaligned::<u128>(addr_of!(id) as *const u128) };
ret ret
} }