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.
This commit is contained in:
Fabian Homborg 2019-04-29 16:55:12 +02:00
parent 8c9359fdd4
commit 43929ced90

View File

@ -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;