diff --git a/libc/getopt/getopt_long.c b/libc/getopt/getopt_long.c index 0b2b15be..a6ec2517 100644 --- a/libc/getopt/getopt_long.c +++ b/libc/getopt/getopt_long.c @@ -154,7 +154,7 @@ int getopt_long(int argc, char* const* argv, const char* shortopts, // Check whether the next argument is the parameter to this option. if ( !option_arg && option->has_arg != no_argument ) { - if ( optind + 1 < argc && argv[optind] && + if ( optind < argc && argv[optind] && (option->has_arg == required_argument || argv[optind][0] != '-') ) option_arg = argv[optind++]; }