From d1f0ce1d57c22f9729d613bffcee0d85c1d606fe Mon Sep 17 00:00:00 2001 From: Wade Mealing Date: Wed, 28 Sep 2011 04:15:24 +1000 Subject: [PATCH] Patch to error and fail instead of using all available memory then crashing to detect the error condition of an unmatched double quote before the end of a file. I couldn't get it to show nice error messages, so this may not be the ideal fix. A test case for this situation has also been added. --- src/comp/syntax/parse/lexer.rs | 6 ++++++ src/test/compile-fail/unbalanced-doublequote.rs | 8 ++++++++ 2 files changed, 14 insertions(+) create mode 100644 src/test/compile-fail/unbalanced-doublequote.rs diff --git a/src/comp/syntax/parse/lexer.rs b/src/comp/syntax/parse/lexer.rs index e36b26c559e98..a1f40ea81c184 100644 --- a/src/comp/syntax/parse/lexer.rs +++ b/src/comp/syntax/parse/lexer.rs @@ -490,8 +490,14 @@ fn next_token_inner(rdr: reader) -> token::token { ret token::LIT_CHAR(c2); } '"' { + let n = rdr.get_chpos(); rdr.bump(); while rdr.curr() != '"' { + if rdr.is_eof() { + rdr.err(#fmt["unterminated double quote string: %s", rdr.get_str_from(n)]); + fail; + } + let ch = rdr.curr(); rdr.bump(); alt ch { diff --git a/src/test/compile-fail/unbalanced-doublequote.rs b/src/test/compile-fail/unbalanced-doublequote.rs new file mode 100644 index 0000000000000..098169e85700a --- /dev/null +++ b/src/test/compile-fail/unbalanced-doublequote.rs @@ -0,0 +1,8 @@ +// -*- rust -*- + +// error-pattern: unterminated double quote string + + +fn main() { + " +}