From ed23315674c0f2808b68b090446a6d0080b22d2e Mon Sep 17 00:00:00 2001 From: Caio Date: Mon, 15 Jul 2024 17:57:39 -0300 Subject: [PATCH] Remove `once_lock` --- Cargo.toml | 1 - src/lib.rs | 19 +++++++------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bdcd0d9..3ce0767 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,6 @@ version = "0.4.7" [dependencies] arbitrary = "1" -once_cell = "1" [build-dependencies] cc = { version = "1.0", features = ["parallel"] } diff --git a/src/lib.rs b/src/lib.rs index 1cd12ee..2c146ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,7 +12,7 @@ #![deny(missing_docs, missing_debug_implementations)] pub use arbitrary; -use once_cell::sync::OnceCell; +use std::sync::OnceLock; /// Indicates whether the input should be kept in the corpus or rejected. This /// should be returned by your fuzz target. If your fuzz target does not return @@ -73,7 +73,10 @@ pub unsafe fn test_input_wrap(data: *const u8, size: usize) -> i32 { } #[doc(hidden)] -pub static RUST_LIBFUZZER_DEBUG_PATH: OnceCell = OnceCell::new(); +pub fn rust_libfuzzer_debug_path() -> &'static Option { + static RUST_LIBFUZZER_DEBUG_PATH: OnceLock> = OnceLock::new(); + RUST_LIBFUZZER_DEBUG_PATH.get_or_init(|| std::env::var("RUST_LIBFUZZER_DEBUG_PATH").ok()) +} #[doc(hidden)] #[export_name = "LLVMFuzzerInitialize"] @@ -91,14 +94,6 @@ pub fn initialize(_argc: *const isize, _argv: *const *const *const u8) -> isize default_hook(panic_info); ::std::process::abort(); })); - - // Initialize the `RUST_LIBFUZZER_DEBUG_PATH` cell with the path so it can be - // reused with little overhead. - if let Ok(path) = std::env::var("RUST_LIBFUZZER_DEBUG_PATH") { - RUST_LIBFUZZER_DEBUG_PATH - .set(path) - .expect("Since this is initialize it is only called once so can never fail"); - } 0 } @@ -213,7 +208,7 @@ macro_rules! fuzz_target { // `cargo fuzz`'s use! // `RUST_LIBFUZZER_DEBUG_PATH` is set in initialization. - if let Some(path) = $crate::RUST_LIBFUZZER_DEBUG_PATH.get() { + if let Some(path) = $crate::rust_libfuzzer_debug_path() { use std::io::Write; let mut file = std::fs::File::create(path) .expect("failed to create `RUST_LIBFUZZER_DEBUG_PATH` file"); @@ -278,7 +273,7 @@ macro_rules! fuzz_target { // `cargo fuzz`'s use! // `RUST_LIBFUZZER_DEBUG_PATH` is set in initialization. - if let Some(path) = $crate::RUST_LIBFUZZER_DEBUG_PATH.get() { + if let Some(path) = $crate::rust_libfuzzer_debug_path() { use std::io::Write; let mut file = std::fs::File::create(path) .expect("failed to create `RUST_LIBFUZZER_DEBUG_PATH` file");