From f9eac1854290a801fb2bfb4c8a67cb01308bea82 Mon Sep 17 00:00:00 2001 From: Langston Barrett Date: Thu, 8 Dec 2022 04:25:18 -0500 Subject: [PATCH] libafl: Remove `set_initial`, `initial_mut` from `MapObserver` trait (#932) These methods force a `MapObserver` to own an initial value, but there's no reason for this to be the case - If you don't need to allow a dynamically-changeable initial value, it might be nice to use `<::Entry as Default>::default()` everywhere and have the compiler statically propagate that value. Not a lot of code used these methods (which seems like a good argument that they aren't a fundamental part of the inteface). --- libafl/src/observers/map.rs | 59 ------------------------------------- 1 file changed, 59 deletions(-) diff --git a/libafl/src/observers/map.rs b/libafl/src/observers/map.rs index 1f9d7e372e..3a535ed5fc 100644 --- a/libafl/src/observers/map.rs +++ b/libafl/src/observers/map.rs @@ -108,14 +108,6 @@ pub trait MapObserver: HasLen + Named + Serialize + serde::de::DeserializeOwned /// Get the initial value for reset() fn initial(&self) -> Self::Entry; - /// Get the initial value for reset() (mutable) - fn initial_mut(&mut self) -> &mut Self::Entry; - - /// Set the initial value for reset() - fn set_initial(&mut self, initial: Self::Entry) { - *self.initial_mut() = initial; - } - /// Reset the map fn reset_map(&mut self) -> Result<(), Error>; @@ -389,11 +381,6 @@ where self.initial } - #[inline] - fn initial_mut(&mut self) -> &mut T { - &mut self.initial - } - fn to_vec(&self) -> Vec { self.as_slice().to_vec() } @@ -776,11 +763,6 @@ where self.initial } - #[inline] - fn initial_mut(&mut self) -> &mut T { - &mut self.initial - } - #[inline] fn get(&self, idx: usize) -> &T { &self.as_slice()[idx] @@ -1050,11 +1032,6 @@ where self.initial } - #[inline] - fn initial_mut(&mut self) -> &mut T { - &mut self.initial - } - #[inline] fn usable_count(&self) -> usize { *self.size.as_ref() @@ -1261,11 +1238,6 @@ where self.base.initial() } - #[inline] - fn initial_mut(&mut self) -> &mut u8 { - self.base.initial_mut() - } - #[inline] fn usable_count(&self) -> usize { self.base.usable_count() @@ -1489,11 +1461,6 @@ where self.base.initial() } - #[inline] - fn initial_mut(&mut self) -> &mut u8 { - self.base.initial_mut() - } - #[inline] fn usable_count(&self) -> usize { self.base.usable_count() @@ -1734,11 +1701,6 @@ where self.initial } - #[inline] - fn initial_mut(&mut self) -> &mut T { - &mut self.initial - } - fn count_bytes(&self) -> u64 { let initial = self.initial(); let mut res = 0; @@ -2090,16 +2052,6 @@ where self.initial } - #[inline] - fn initial_mut(&mut self) -> &mut T { - &mut self.initial - } - - #[inline] - fn set_initial(&mut self, initial: T) { - self.initial = initial; - } - /// Reset the map #[inline] fn reset_map(&mut self) -> Result<(), Error> { @@ -2478,17 +2430,6 @@ pub mod pybind { mapob_unwrap_me!($wrapper_name, self.wrapper, m, { m.initial() }) } - #[inline] - fn initial_mut(&mut self) -> &mut $datatype { - let ptr = mapob_unwrap_me_mut!($wrapper_name, self.wrapper, m, { m.initial_mut() as *mut $datatype }); - unsafe { ptr.as_mut().unwrap() } - } - - #[inline] - fn set_initial(&mut self, initial: $datatype) { - mapob_unwrap_me_mut!($wrapper_name, self.wrapper, m, { m.set_initial(initial) }); - } - #[inline] fn reset_map(&mut self) -> Result<(), Error> { mapob_unwrap_me_mut!($wrapper_name, self.wrapper, m, { m.reset_map() })