Skip to content

Commit

Permalink
test for nan from exp
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Sep 11, 2023
1 parent 4bac9f4 commit 3884403
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions fuzz/fuzz_targets/compare_to_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ pub fn values_equal(jiter_value: &JiterValue, serde_value: &SerdeValue) -> bool
fn floats_approx(f1: Option<f64>, f2: Option<f64>) -> bool {
match (f1, f2) {
(Some(f1), Some(f2)) => {
if f1.is_nan() {
// this happens for strings like `"5 + "0" * 500 + "E-6666"`, I think jiter is more correct than
// serde
return true
}
let mut threshold = f1.abs() / 1_000_000_f64;
if threshold < 0.000_000_1 {
threshold = 0.000_000_1;
Expand Down
10 changes: 10 additions & 0 deletions tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,13 @@ fn jiter_wrong_type() {
Err(other_err) => panic!("unexpected error: {:?}", other_err),
}
}

#[test]
fn test_crazy_massive_int() {
let mut s = "5".to_string();
s.push_str(&"0".repeat(500));
s.push_str("E-6666");
let mut jiter = Jiter::new(s.as_bytes());
assert!(jiter.next_float().unwrap().is_nan());
jiter.finish().unwrap();
}

0 comments on commit 3884403

Please sign in to comment.