12
12
#![ deny( missing_docs, missing_debug_implementations) ]
13
13
14
14
pub use arbitrary;
15
- use once_cell :: sync:: OnceCell ;
15
+ use std :: sync:: OnceLock ;
16
16
17
17
/// Indicates whether the input should be kept in the corpus or rejected. This
18
18
/// 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 {
73
73
}
74
74
75
75
#[ doc( hidden) ]
76
- pub static RUST_LIBFUZZER_DEBUG_PATH : OnceCell < String > = OnceCell :: new ( ) ;
76
+ pub fn rust_libfuzzer_debug_path ( ) -> & ' static Option < String > {
77
+ static RUST_LIBFUZZER_DEBUG_PATH : OnceLock < Option < String > > = OnceLock :: new ( ) ;
78
+ RUST_LIBFUZZER_DEBUG_PATH . get_or_init ( || std:: env:: var ( "RUST_LIBFUZZER_DEBUG_PATH" ) . ok ( ) )
79
+ }
77
80
78
81
#[ doc( hidden) ]
79
82
#[ export_name = "LLVMFuzzerInitialize" ]
@@ -91,14 +94,6 @@ pub fn initialize(_argc: *const isize, _argv: *const *const *const u8) -> isize
91
94
default_hook ( panic_info) ;
92
95
:: std:: process:: abort ( ) ;
93
96
} ) ) ;
94
-
95
- // Initialize the `RUST_LIBFUZZER_DEBUG_PATH` cell with the path so it can be
96
- // reused with little overhead.
97
- if let Ok ( path) = std:: env:: var ( "RUST_LIBFUZZER_DEBUG_PATH" ) {
98
- RUST_LIBFUZZER_DEBUG_PATH
99
- . set ( path)
100
- . expect ( "Since this is initialize it is only called once so can never fail" ) ;
101
- }
102
97
0
103
98
}
104
99
@@ -213,7 +208,7 @@ macro_rules! fuzz_target {
213
208
// `cargo fuzz`'s use!
214
209
215
210
// `RUST_LIBFUZZER_DEBUG_PATH` is set in initialization.
216
- if let Some ( path) = $crate:: RUST_LIBFUZZER_DEBUG_PATH . get ( ) {
211
+ if let Some ( path) = $crate:: rust_libfuzzer_debug_path ( ) {
217
212
use std:: io:: Write ;
218
213
let mut file = std:: fs:: File :: create( path)
219
214
. expect( "failed to create `RUST_LIBFUZZER_DEBUG_PATH` file" ) ;
@@ -278,7 +273,7 @@ macro_rules! fuzz_target {
278
273
// `cargo fuzz`'s use!
279
274
280
275
// `RUST_LIBFUZZER_DEBUG_PATH` is set in initialization.
281
- if let Some ( path) = $crate:: RUST_LIBFUZZER_DEBUG_PATH . get ( ) {
276
+ if let Some ( path) = $crate:: rust_libfuzzer_debug_path ( ) {
282
277
use std:: io:: Write ;
283
278
let mut file = std:: fs:: File :: create( path)
284
279
. expect( "failed to create `RUST_LIBFUZZER_DEBUG_PATH` file" ) ;
0 commit comments