From d8464c8f916cc8f5836bbf8c400bc3f9bf24501b Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 29 Jun 2020 07:26:18 -0700 Subject: [PATCH] Use external float parser rather than rustc's Per https://github.com/rust-lang/rust/issues/31407, rustc's float parser may drop some valid float literals. For now use an external parser that does not have these problems. Closes #147 --- libslide/Cargo.toml | 1 + libslide/src/scanner.rs | 5 ++++- ...MDA0ABowMDAwMDAwMC4wMDU1NTU1NTU1NTU1NTU1NTU1NT | Bin 0 -> 367 bytes slide/src/test/ui/giant_float.slide | 14 ++++++++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 slide/fuzz/seed/MTEAGjAwMDAwMDAwLjAwMDAxMQAaMDAwMDAwMDAuMDAwMDAwMDA0ABowMDAwMDAwMC4wMDAwMDAwMDAwMDA0ABowMDAwMDAwMC4wMDU1NTU1NTU1NTU1NTU1NTU1NT create mode 100644 slide/src/test/ui/giant_float.slide diff --git a/libslide/Cargo.toml b/libslide/Cargo.toml index 1f4e4fbdc..deaf5f108 100644 --- a/libslide/Cargo.toml +++ b/libslide/Cargo.toml @@ -26,6 +26,7 @@ required-features = ["benchmark-internals"] [dependencies] rug = "1.9.0" +strtod = "0.0.1" [dependencies.num-traits] version = "0.2" diff --git a/libslide/src/scanner.rs b/libslide/src/scanner.rs index f1ce918d5..a02b4523a 100644 --- a/libslide/src/scanner.rs +++ b/libslide/src/scanner.rs @@ -1,6 +1,7 @@ pub mod types; use crate::diagnostics::Diagnostic; +use strtod::strtod; use types::TokenType as TT; pub use types::*; @@ -123,7 +124,9 @@ impl Scanner { float_str.push(*self.next().unwrap()); float_str.push_str(&self.collect_while(|c| c.is_digit(10))); } - let float = float_str.parse::().unwrap(); + // TODO(https://github.com/rust-lang/rust/issues/31407): rustc's float parser may drop some + // valid float literals. For now, use an external parser. + let float = strtod(&float_str).unwrap(); self.output.push(tok!(TT::Float(float), (start, self.pos))); } diff --git a/slide/fuzz/seed/MTEAGjAwMDAwMDAwLjAwMDAxMQAaMDAwMDAwMDAuMDAwMDAwMDA0ABowMDAwMDAwMC4wMDAwMDAwMDAwMDA0ABowMDAwMDAwMC4wMDU1NTU1NTU1NTU1NTU1NTU1NT b/slide/fuzz/seed/MTEAGjAwMDAwMDAwLjAwMDAxMQAaMDAwMDAwMDAuMDAwMDAwMDA0ABowMDAwMDAwMC4wMDAwMDAwMDAwMDA0ABowMDAwMDAwMC4wMDU1NTU1NTU1NTU1NTU1NTU1NT new file mode 100644 index 0000000000000000000000000000000000000000..c03c5f986f66587a4c179e74f9884e5ff733dc09 GIT binary patch literal 367 zcmXpsWRNm|0zD9Ih%NvUG(l4Y5(5ELaZ@Y+qRxO8Mq{xJS;z#LLnIsGS^|p6H`qi5 E06ITL;Q#;t literal 0 HcmV?d00001 diff --git a/slide/src/test/ui/giant_float.slide b/slide/src/test/ui/giant_float.slide new file mode 100644 index 000000000..af8db5ac9 --- /dev/null +++ b/slide/src/test/ui/giant_float.slide @@ -0,0 +1,14 @@ +===in +000000000.0055555555555555555555000005555555555555555555455555555555555555555555555555555555555555550000005555555555555555555555555555555455555555555555555555555555555555555555555555550000004 +===in + +~~~stdout +0.005555555555555556 +~~~stdout + +~~~stderr +~~~stderr + +~~~exitcode +0 +~~~exitcode