Skip to content

Commit f375391

Browse files
wmealingbrson
authored andcommitted
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.
1 parent a96b16e commit f375391

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/comp/syntax/parse/lexer.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,15 @@ fn next_token_inner(rdr: reader) -> token::token {
490490
ret token::LIT_CHAR(c2);
491491
}
492492
'"' {
493+
let n = rdr.get_chpos();
493494
rdr.bump();
494495
while rdr.curr() != '"' {
496+
if rdr.is_eof() {
497+
rdr.err(#fmt["unterminated double quote string: %s",
498+
rdr.get_str_from(n)]);
499+
fail;
500+
}
501+
495502
let ch = rdr.curr();
496503
rdr.bump();
497504
alt ch {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// -*- rust -*-
2+
3+
// error-pattern: unterminated double quote string
4+
5+
6+
fn main() {
7+
"
8+
}

0 commit comments

Comments
 (0)