Date: Thu, 04 Dec 2025 11:33:01 +0000 From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 291374] getopt(3) GNU extension wrong behavior Message-ID: <bug-291374-227-q5DcQDUf1G@https.bugs.freebsd.org/bugzilla/> In-Reply-To: <bug-291374-227@https.bugs.freebsd.org/bugzilla/>
index | next in thread | previous in thread | raw e-mail
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=291374 Simon Wollwage <rootnode+freebsd@wollwage.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |rootnode+freebsd@wollwage.c | |om --- Comment #3 from Simon Wollwage <rootnode+freebsd@wollwage.com> --- (In reply to Jose Luis Duran from comment #2) I think I found the issue. It's in this part: else if (oli[2] == ':') /* * GNU Extension, for optional arguments if the rest of * the argument is empty, we return NULL */ optarg = NULL; So, if place is NULL (because of the space), it just sets the arg to NULL. Next iteration it would see just the 14 as an option and fails. Changing it to something like this should fix it: else if (oli[2] == ':') { /* * GNU Extension, for optional arguments if the rest of * the argument is empty, we return NULL */ if (nargc > optind + 1 && nargv[optind + 1][0] != '-') { optarg = nargv[++optind]; } else { optarg = NULL; } } But I am new to this and am not sure how to compile the stdlib part and test it. If I could get some guidance on that part I would be happy to make my first contribution. -- You are receiving this mail because: You are the assignee for the bug.home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-291374-227-q5DcQDUf1G>
