fix integer underflow in ast.fullPtrType (#829)

This commit is contained in:
Techatrix 2022-12-16 21:24:25 +01:00 committed by GitHub
parent e1973afafc
commit 5d6f23b5f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,18 +9,15 @@ const full = Ast.full;
fn fullPtrType(tree: Ast, info: full.PtrType.Components) full.PtrType { fn fullPtrType(tree: Ast, info: full.PtrType.Components) full.PtrType {
const token_tags = tree.tokens.items(.tag); const token_tags = tree.tokens.items(.tag);
// TODO: looks like stage1 isn't quite smart enough to handle enum const size: std.builtin.Type.Pointer.Size = switch (token_tags[info.main_token]) {
// literals in some places here
const Size = std.builtin.Type.Pointer.Size;
const size: Size = switch (token_tags[info.main_token]) {
.asterisk, .asterisk,
.asterisk_asterisk, .asterisk_asterisk,
=> switch (token_tags[info.main_token + 1]) { => switch (token_tags[info.main_token + 1]) {
.r_bracket, .colon => .Many, .r_bracket, .colon => .Many,
.identifier => if (token_tags[info.main_token - 1] == .l_bracket) Size.C else .One, .identifier => if (info.main_token != 0 and token_tags[info.main_token - 1] == .l_bracket) .C else .One,
else => .One, else => .One,
}, },
.l_bracket => Size.Slice, .l_bracket => .Slice,
else => unreachable, else => unreachable,
}; };
var result: full.PtrType = .{ var result: full.PtrType = .{