Skip to content

Commit 2a728f6

Browse files
squeek502andrewrk
authored andcommitted
tokenizer: Fix index-out-of-bounds on string_literal_backslash right before EOF
1 parent 380ca26 commit 2a728f6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/std/zig/tokenizer.zig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ pub const Tokenizer = struct {
700700
},
701701

702702
.string_literal_backslash => switch (c) {
703-
'\n' => {
703+
0, '\n' => {
704704
result.tag = .invalid;
705705
break;
706706
},
@@ -1919,6 +1919,10 @@ test "tokenizer - invalid builtin identifiers" {
19191919
try testTokenize("@0()", &.{ .invalid, .integer_literal, .l_paren, .r_paren });
19201920
}
19211921

1922+
test "tokenizer - backslash before eof in string literal" {
1923+
try testTokenize("\"\\", &.{.invalid});
1924+
}
1925+
19221926
fn testTokenize(source: [:0]const u8, expected_tokens: []const Token.Tag) !void {
19231927
var tokenizer = Tokenizer.init(source);
19241928
for (expected_tokens) |expected_token_id| {

0 commit comments

Comments
 (0)