authorgravatar for techatrix@mailbox.orgTechatrix <techatrix@mailbox.org> 2022-12-18 05:59:43+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-12-18 04:59:43+00:00
log4809e0ea7f53d1b56cbc4c6e62e4b8ea40936d44
tree51ae7741cafe23082b9727780a531a92048752ea
parent901c3e96368bd9fa9ee9858c0295ee05ef1d7146
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

fix potential integer underflow in std.zig.Ast.fullCall


2 files changed, 10 insertions(+), 3 deletions(-)

lib/std/zig/Ast.zig+3-3
...@@ -2189,9 +2189,9 @@ fn fullCall(tree: Ast, info: full.Call.Components) full.Call {...@@ -2189,9 +2189,9 @@ fn fullCall(tree: Ast, info: full.Call.Components) full.Call {
2189 .ast = info,2189 .ast = info,
2190 .async_token = null,2190 .async_token = null,
2191 };2191 };
2192 const maybe_async_token = tree.firstToken(info.fn_expr) - 1;2192 const first_token = tree.firstToken(info.fn_expr);
2193 if (token_tags[maybe_async_token] == .keyword_async) {2193 if (first_token != 0 and token_tags[first_token - 1] == .keyword_async) {
2194 result.async_token = maybe_async_token;2194 result.async_token = first_token - 1;
2195 }2195 }
2196 return result;2196 return result;
2197}2197}
lib/std/zig/parser_test.zig+7
...@@ -214,6 +214,13 @@ test "zig fmt: top-level fields" {...@@ -214,6 +214,13 @@ test "zig fmt: top-level fields" {
214 );214 );
215}215}
216216
217test "zig fmt: top-level tuple function call type" {
218 try testCanonical(
219 \\foo()
220 \\
221 );
222}
223
217test "zig fmt: C style containers" {224test "zig fmt: C style containers" {
218 try testError(225 try testError(
219 \\struct Foo {226 \\struct Foo {