commit 4809e0ea7f53d1b56cbc4c6e62e4b8ea40936d44 (tree)
parent 901c3e96368bd9fa9ee9858c0295ee05ef1d7146
Author: Techatrix <19954306+Techatrix@users.noreply.github.com>
Date: Sun, 18 Dec 2022 05:59:43 +0100
fix potential integer underflow in std.zig.Ast.fullCall
Diffstat:
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/lib/std/zig/Ast.zig b/lib/std/zig/Ast.zig
@@ -2189,9 +2189,9 @@ fn fullCall(tree: Ast, info: full.Call.Components) full.Call {
.ast = info,
.async_token = null,
};
- const maybe_async_token = tree.firstToken(info.fn_expr) - 1;
- if (token_tags[maybe_async_token] == .keyword_async) {
- result.async_token = maybe_async_token;
+ const first_token = tree.firstToken(info.fn_expr);
+ if (first_token != 0 and token_tags[first_token - 1] == .keyword_async) {
+ result.async_token = first_token - 1;
}
return result;
}
diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig
@@ -214,6 +214,13 @@ test "zig fmt: top-level fields" {
);
}
+test "zig fmt: top-level tuple function call type" {
+ try testCanonical(
+ \\foo()
+ \\
+ );
+}
+
test "zig fmt: C style containers" {
try testError(
\\struct Foo {