From f375391cb61bb0a06f3e2fe80aac070ea4c83fc1 Mon Sep 17 00:00:00 2001 From: Wade Mealing Date: Wed, 28 Sep 2011 04:15:24 +1000 Subject: [PATCH] Patch to error instead of crashing when parsing unmatched double quotes 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 | 7 +++++++ src/test/compile-fail/unbalanced-doublequote.rs | 8 ++++++++ 2 files changed, 15 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 e36b26c559e..f10701ceba5 100644 --- a/src/comp/syntax/parse/lexer.rs +++ b/src/comp/syntax/parse/lexer.rs @@ -490,8 +490,15 @@ 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 00000000000..38df31a2b64 --- /dev/null +++ b/src/test/compile-fail/unbalanced-doublequote.rs @@ -0,0 +1,8 @@ +// -*- rust -*- + +// error-pattern: unterminated double quote string + + +fn main() { + " +}