From 43929ced90692cce25f080144b55e161328211e3 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Mon, 29 Apr 2019 16:55:12 +0200 Subject: [PATCH] src/builtin_argparse: Work around wgetopt crash If on the last argument, and it was an unrecognized option, we can't call `wgetopt_long()` again, or it'll crash. --- src/builtin_argparse.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/builtin_argparse.cpp b/src/builtin_argparse.cpp index 54e129c36..3b38c0e0b 100644 --- a/src/builtin_argparse.cpp +++ b/src/builtin_argparse.cpp @@ -574,6 +574,8 @@ static int argparse_parse_flags(parser_t &parser, argparse_cmd_opts_t &opts, // This allows reusing the same argv in multiple argparse calls, // or just ignoring the error (e.g. in completions). opts.argv.push_back(arg_contents - 1); + // Work around weirdness with wgetopt, which crashes if we `continue` here. + if (w.woptind == argc) break; } if (retval != STATUS_CMD_OK) return retval; long_idx = -1;