Skip to content

Commit 6243b68

Browse files
Introduce BoolMutator (#2926)
1 parent 6648bc9 commit 6243b68

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

libafl/src/mutators/mod.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,3 +407,22 @@ impl Named for NopMutator {
407407
&Cow::Borrowed("NopMutator")
408408
}
409409
}
410+
411+
/// [`Mutator`] that flips a boolean value.
412+
///
413+
/// Mostly useful in combination with [`mapping::MappingMutator`]s.
414+
#[derive(Debug)]
415+
pub struct BoolMutator;
416+
417+
impl<S> Mutator<bool, S> for BoolMutator {
418+
fn mutate(&mut self, _state: &mut S, input: &mut bool) -> Result<MutationResult, Error> {
419+
*input = !*input;
420+
Ok(MutationResult::Mutated)
421+
}
422+
}
423+
424+
impl Named for BoolMutator {
425+
fn name(&self) -> &Cow<'static, str> {
426+
&Cow::Borrowed("BoolMutator")
427+
}
428+
}

0 commit comments

Comments
 (0)