diff --git a/libs/libc/unistd/lib_getopt_common.c b/libs/libc/unistd/lib_getopt_common.c index c84d9a65504..be3e22a21a5 100644 --- a/libs/libc/unistd/lib_getopt_common.c +++ b/libs/libc/unistd/lib_getopt_common.c @@ -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 */