diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2013-04-08 00:39:28 +1000 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2013-04-08 16:40:40 +1000 |
| commit | 0c2ceb1a2e93e2e7624d384e19da6783cbb720ba (patch) | |
| tree | f5eb8790214a06ee59a45c6e741a070dba44edbb /src | |
| parent | 41c6f67109ed8adee209f28ce7f9dbe1432a45bd (diff) | |
| download | rust-0c2ceb1a2e93e2e7624d384e19da6783cbb720ba.tar.gz rust-0c2ceb1a2e93e2e7624d384e19da6783cbb720ba.zip | |
libsyntax: fail lexing with an error message on an int literal larger than 2^64.
Stops an ICE. Closes #5544.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libsyntax/parse/lexer.rs | 11 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-5544-a.rs | 14 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-5544-b.rs | 14 |
3 files changed, 37 insertions, 2 deletions
diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index 5e06ecf6090..b6ec15d8641 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -442,7 +442,11 @@ fn scan_number(c: char, rdr: @mut StringReader) -> token::Token { if str::len(num_str) == 0u { rdr.fatal(~"no valid digits found for number"); } - let parsed = u64::from_str_radix(num_str, base as uint).get(); + let parsed = match u64::from_str_radix(num_str, base as uint) { + Some(p) => p, + None => rdr.fatal(~"int literal is too large") + }; + match tp { either::Left(t) => return token::LIT_INT(parsed as i64, t), either::Right(t) => return token::LIT_UINT(parsed, t) @@ -503,7 +507,10 @@ fn scan_number(c: char, rdr: @mut StringReader) -> token::Token { if str::len(num_str) == 0u { rdr.fatal(~"no valid digits found for number"); } - let parsed = u64::from_str_radix(num_str, base as uint).get(); + let parsed = match u64::from_str_radix(num_str, base as uint) { + Some(p) => p, + None => rdr.fatal(~"int literal is too large") + }; debug!("lexing %s as an unsuffixed integer literal", num_str); diff --git a/src/test/compile-fail/issue-5544-a.rs b/src/test/compile-fail/issue-5544-a.rs new file mode 100644 index 00000000000..42a18ba5fb7 --- /dev/null +++ b/src/test/compile-fail/issue-5544-a.rs @@ -0,0 +1,14 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let _i = 18446744073709551616; // 2^64 + //~^ ERROR int literal is too large +} diff --git a/src/test/compile-fail/issue-5544-b.rs b/src/test/compile-fail/issue-5544-b.rs new file mode 100644 index 00000000000..bbe43e652a8 --- /dev/null +++ b/src/test/compile-fail/issue-5544-b.rs @@ -0,0 +1,14 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let _i = 0xff_ffff_ffff_ffff_ffff; + //~^ ERROR int literal is too large +} |
