Skip to content

Commit 16a4ff8

Browse files
author
Simon Wollwage
committed
lib/libc: fix bug in parsing in getopt
getopt had an issue when parsing optional arguments if they had a space between the opion and its value. Request: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=291374 Signed-off-by: Simon Wollwage <[email protected]>
1 parent 3f10e59 commit 16a4ff8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/libc/stdlib/getopt.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ getopt(int nargc, char * const nargv[], const char *ostr)
112112
* GNU Extension, for optional arguments if the rest of
113113
* the argument is empty, we return NULL
114114
*/
115-
optarg = NULL;
115+
if (nargc > (optind + 1) && nargv[optind + 1][0] != '-') {
116+
optarg = nargv[++optind];
117+
} else {
118+
optarg = NULL;
119+
}
116120
else if (nargc > ++optind)
117121
optarg = nargv[optind];
118122
else {

0 commit comments

Comments
 (0)