libc/unistd: getopt: Use argc to end parsing

It should end parsing with argc even the argv are remaining
or it may access to invalid address.

Signed-off-by: Takumi Ando <t-ando@advaly.co.jp>
This commit is contained in:
Takumi Ando 2021-12-15 17:26:50 +09:00 committed by Xiang Xiao
parent b11833cbba
commit d0dd2684ce

View File

@ -393,7 +393,7 @@ int getopt_common(int argc, FAR char * const argv[],
/* Check for the end of the argument list */
go->go_optptr = argv[go->go_optind];
go->go_optptr = go->go_optind < argc ? argv[go->go_optind] : NULL;
if (!go->go_optptr)
{
/* There are no more arguments, we are finished */