[Bug 291374] getopt(3) GNU extension wrong behavior
- In reply to: bugzilla-noreply_a_freebsd.org: "[Bug 291374] getopt(3) GNU extension wrong behavior"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 04 Dec 2025 11:33:01 UTC
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.