mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 04:48:20 +00:00
parse.zig: better c pointer prefix parsing, don't index out of bounds on eof
This commit is contained in:
parent
ba7f40c430
commit
2ed9288246
@ -1584,18 +1584,13 @@ const Parser = struct {
|
||||
_ = p.nextToken();
|
||||
const asterisk = p.nextToken();
|
||||
var sentinel: Node.Index = 0;
|
||||
prefix: {
|
||||
if (p.eatToken(.identifier)) |ident| {
|
||||
const token_slice = p.source[p.token_starts[ident]..][0..2];
|
||||
if (!std.mem.eql(u8, token_slice, "c]")) {
|
||||
p.tok_i -= 1;
|
||||
} else {
|
||||
break :prefix;
|
||||
}
|
||||
}
|
||||
if (p.eatToken(.colon)) |_| {
|
||||
sentinel = try p.expectExpr();
|
||||
if (p.eatToken(.identifier)) |ident| {
|
||||
const ident_slice = p.source[p.token_starts[ident]..p.token_starts[ident + 1]];
|
||||
if (!std.mem.eql(u8, std.mem.trimRight(u8, ident_slice, &std.ascii.spaces), "c")) {
|
||||
p.tok_i -= 1;
|
||||
}
|
||||
} else if (p.eatToken(.colon)) |_| {
|
||||
sentinel = try p.expectExpr();
|
||||
}
|
||||
_ = try p.expectToken(.r_bracket);
|
||||
const mods = try p.parsePtrModifiers();
|
||||
|
||||
@ -5259,6 +5259,14 @@ test "recovery: nonfinal varargs" {
|
||||
});
|
||||
}
|
||||
|
||||
test "recovery: eof in c pointer" {
|
||||
try testError(
|
||||
\\const Ptr = [*c
|
||||
, &[_]Error{
|
||||
.expected_token,
|
||||
});
|
||||
}
|
||||
|
||||
const std = @import("std");
|
||||
const mem = std.mem;
|
||||
const print = std.debug.print;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user