Skip to content

Commit

Permalink
Merge pull request #120 from c410-f3r/master
Browse files Browse the repository at this point in the history
Remove `once_cell`
  • Loading branch information
fitzgen authored Jul 15, 2024
2 parents 9848925 + ed23315 commit c8275d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ version = "0.4.7"

[dependencies]
arbitrary = "1"
once_cell = "1"

[build-dependencies]
cc = { version = "1.0", features = ["parallel"] }
Expand Down
19 changes: 7 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<String> = OnceCell::new();
pub fn rust_libfuzzer_debug_path() -> &'static Option<String> {
static RUST_LIBFUZZER_DEBUG_PATH: OnceLock<Option<String>> = OnceLock::new();
RUST_LIBFUZZER_DEBUG_PATH.get_or_init(|| std::env::var("RUST_LIBFUZZER_DEBUG_PATH").ok())
}

#[doc(hidden)]
#[export_name = "LLVMFuzzerInitialize"]
Expand All @@ -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
}

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit c8275d1

Please sign in to comment.