Skip to content

Commit

Permalink
reformat fuzzer
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-o-how committed Feb 10, 2025
1 parent ad09f81 commit f2571b3
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions fuzz/fuzz_targets/deserialize_br.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ use libfuzzer_sys::fuzz_target;

fuzz_target!(|data: &[u8]| {
let mut allocator = Allocator::new();
let program = match node_from_bytes_backrefs(&mut allocator, data) {
Err(_) => {
assert!(node_from_bytes_backrefs_old(&mut allocator, data).is_err());
return;
let res1 = node_from_bytes_backrefs(&mut allocator, data);
let node_count = allocator.node_count();
let res2 = node_from_bytes_backrefs_old(&mut allocator, data);
// check that the new implementation creates the same number of nodes as the old one
assert_eq!(node_count * 2, allocator.node_count());
match (res1, res2) {
(Err(e1), Err(e2)) => {
assert_eq!(e1, e2);
}
Ok(r) => r,
};

let program_old = node_from_bytes_backrefs_old(&mut allocator, data).unwrap();
assert!(node_eq::node_eq(&allocator, program, program_old));
(Ok(n1), Ok(n2)) => {
assert!(node_eq::node_eq(&allocator, n1, n2));
}
_ => {
panic!("mismatching results");
}
}
});

0 comments on commit f2571b3

Please sign in to comment.