From ba4d6548edeb7c79c5e8e7939997c618b6477901 Mon Sep 17 00:00:00 2001 From: Chris Hennick Date: Sat, 13 May 2023 14:40:23 -0700 Subject: [PATCH] Refactor FileOptions generation using arbitrary_loop --- src/write.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/write.rs b/src/write.rs index 478cba54..c129c919 100644 --- a/src/write.rs +++ b/src/write.rs @@ -152,18 +152,16 @@ impl arbitrary::Arbitrary<'_> for FileOptions { central_extra_data: Vec::with_capacity(u16::MAX as usize), alignment: u8::arbitrary(u)? as u16 + 1, }; - #[derive(arbitrary::Arbitrary)] - struct ExtraDataField { - header_id: u16, - data: Vec, - central_only: bool, - } - let extra_data = Vec::::arbitrary(u)?; - for field in extra_data { + u.arbitrary_loop(None, Some(16383), || { options - .add_extra_data(field.header_id, field.data.as_slice(), field.central_only) + .add_extra_data( + u16::arbitrary(u)?, + Vec::::arbitrary(u)?, + bool::arbitrary(u)?, + ) .map_err(|_| arbitrary::Error::IncorrectFormat)?; - } + Ok(core::ops::ControlFlow::Continue(())) + }); Ok(options) } }