]> git.lizzy.rs Git - rust.git/commitdiff
Patch to error instead of crashing when parsing unmatched double quotes
authorWade Mealing <wmealing@gmail.com>
Tue, 27 Sep 2011 18:15:24 +0000 (04:15 +1000)
committerBrian Anderson <banderson@mozilla.com>
Wed, 28 Sep 2011 06:20:31 +0000 (23:20 -0700)
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
src/test/compile-fail/unbalanced-doublequote.rs [new file with mode: 0644]

index e36b26c559e989c854209a8378787ae80ba6e3a5..f10701ceba588cc72786808b97323b012637d769 100644 (file)
@@ -490,8 +490,15 @@ fn binop(rdr: reader, op: token::binop) -> 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 (file)
index 0000000..38df31a
--- /dev/null
@@ -0,0 +1,8 @@
+// -*- rust -*-
+
+// error-pattern: unterminated double quote string
+
+
+fn main() {
+    "
+}