Skip to content

Commit

Permalink
fix macro issue
Browse files Browse the repository at this point in the history
replace once_cell with std LazyLock
  • Loading branch information
R9295 committed Jan 30, 2025
1 parent 843ac96 commit 00c7a91
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ members = [
[dependencies]
afl = { version = "0.15.11", default-features = false, optional = true }
anyhow = { version = "1.0.83", optional = true }
arbitrary = "1.4.1"
cargo_metadata = { version = "0.18.1", optional = true }
clap = { version = "4.5.4", features = ["cargo", "derive", "env"], optional = true }
console = { version = "0.15.8", optional = true }
Expand Down
32 changes: 18 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#![doc = include_str!("../README.md")]
#[cfg(feature = "afl")]
pub use afl::fuzz as afl_fuzz;
#[cfg(feature = "afl")]
pub use once_cell;
#[cfg(feature = "coverage")]
pub use fork;
#[cfg(feature = "honggfuzz")]
pub use honggfuzz::fuzz as honggfuzz_fuzz;
//#[cfg(not(any(feature = "afl", feature = "honggfuzz")))]
pub use arbitrary;

// This is our inner harness handler function for the runner.
// We open the input file and feed the data to the harness closure.
Expand Down Expand Up @@ -137,8 +133,8 @@ macro_rules! read_args_and_fuzz {
/// # }
/// ```
#[macro_export]
#[cfg(not(any(feature = "afl", feature = "honggfuzz")))]
macro_rules! fuzz {
#[cfg(not(feature = "coverage"))]
macro_rules! inner_fuzz {
(|$buf:ident| $body:block) => {
$crate::read_args_and_fuzz!(|$buf| $body);
};
Expand All @@ -148,8 +144,8 @@ macro_rules! fuzz {
(|$buf:ident: $dty: ty| $body:block) => {
$crate::read_args_and_fuzz!(|$buf| {
let $buf: $dty = {
let mut data = $crate::arbitrary::Unstructured::new($buf);
if let Ok(d) = $crate::arbitrary::Arbitrary::arbitrary(&mut data).map_err(|_| "") {
let mut data = ::arbitrary::Unstructured::new($buf);
if let Ok(d) = ::arbitrary::Arbitrary::arbitrary(&mut data).map_err(|_| "") {
d
} else {
return;
Expand All @@ -160,18 +156,26 @@ macro_rules! fuzz {
};
}

/// We need this wrapper
#[macro_export]
#[cfg(feature = "afl")]
#[cfg(not(any(feature = "afl", feature = "honggfuzz")))]
macro_rules! fuzz {
(|$buf:ident: $ty:ty| $body:block) => {{
static USE_ARGS: $crate::once_cell::sync::Lazy<bool> = $crate::once_cell::sync::Lazy::new(|| std::env::args().len() > 1);
( $($x:tt)* ) => {
$crate::inner_fuzz!($($x)*);
}
}

#[macro_export]
#[cfg(feature = "afl")]
macro_rules! fuzz {
( $($x:tt)* ) => {
static USE_ARGS: std::sync::LazyLock<bool> = std::sync::LazyLock::new(|| std::env::args().len() > 1);
if *USE_ARGS {
$crate::read_args_and_fuzz!(|$buf| $body);
$crate::inner_fuzz!($($x)*);
} else {
$crate::afl_fuzz!(|$buf: $ty| $body);
$crate::afl_fuzz!($($x)*);
}
}};
};
}

#[macro_export]
Expand Down

0 comments on commit 00c7a91

Please sign in to comment.