Resize MapFeedbackMetadata with observer.initial() (#718)

This commit is contained in:
Dongjia Zhang 2022-08-05 09:05:15 +02:00 committed by GitHub
parent 12052b5f1c
commit 3dfdba2ddc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -314,6 +314,15 @@ where
}
Ok(())
}
/// Reset the map with any value
pub fn reset_with_value(&mut self, value: T) -> Result<(), Error> {
let cnt = self.history_map.len();
for i in 0..cnt {
self.history_map[i] = value;
}
Ok(())
}
}
/// The most common AFL-like feedback type
@ -352,6 +361,8 @@ where
S: HasNamedMetadata + HasClientPerfMonitor + Debug,
{
fn init_state(&mut self, state: &mut S) -> Result<(), Error> {
// Initialize `MapFeedbackMetadata` with an empty vector and add it to the state.
// The `MapFeedbackMetadata` would be resized on-demand in `is_interesting`
state.add_named_metadata(MapFeedbackMetadata::<T>::default(), &self.name);
Ok(())
}
@ -659,7 +670,7 @@ where
.unwrap();
let len = observer.len();
if map_state.history_map.len() < len {
map_state.history_map.resize(len, T::default());
map_state.history_map.resize(len, observer.initial());
}
let history_map = map_state.history_map.as_mut_slice();