From 87807d53dd711d0452e6e963243986c7d885e987 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Fri, 2 Oct 2020 18:20:55 +0200 Subject: [PATCH] stage2: Fix arg processing for zig run * Stop parsing arguments after `--` * Calculate the correct index for the first argument after `--` --- src/main.zig | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.zig b/src/main.zig index cd8fefce87..7564342739 100644 --- a/src/main.zig +++ b/src/main.zig @@ -525,7 +525,7 @@ fn buildOutputType( //} const args = all_args[2..]; var i: usize = 0; - while (i < args.len) : (i += 1) { + args_loop: while (i < args.len) : (i += 1) { const arg = args[i]; if (mem.startsWith(u8, arg, "-")) { if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) { @@ -533,7 +533,10 @@ fn buildOutputType( return cleanExit(); } else if (mem.eql(u8, arg, "--")) { if (arg_mode == .run) { - runtime_args_start = i + 1; + // The index refers to all_args so skip `zig` `run` + // and `--` + runtime_args_start = i + 3; + break :args_loop; } else { fatal("unexpected end-of-parameter mark: --", .{}); }