-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for optind in getopt on musl libc. #31946
Conversation
points to the last non-opt argument of argv, but in the case where there are only options optind does not go beyond argc, except on musl libc, where it becomes argc + 1.
Should a bug report be filed with musl as well? |
I don't know which one is correct though, e.g. from https://www.gnu.org/software/libc/manual/html_node/Using-Getopt.html#Using-Getopt:
which could be interpreted as Lines 50 to 52 in 5486cc2
|
IMO it's a bug that it points off the end of the array; I think it's worthwhile notifying the musl developers. They're probably aware and they'll probably close it as wontfix, but might as well try to be good citizens. |
The POSIX
My reading is that on a successful call POSIX requires |
As noted by @stevengj, POSIX is very explicit about requiring this behavior; it's not a bug in musl:
If other implementations are not doing this it should probably be reported as a bug against them. |
This fixes
julia/test/cmdlineargs.jl
Line 258 in 11ce4d1
julia/test/cmdlineargs.jl
Line 263 in 11ce4d1
i.e. the bug only shows where there are a last option with a default value.
On exit
optind
points to the last non-opt argument ofargv
, but in the case where there are only optionsoptind
does not go beyondargc
, except on musl libc, where it becomesargc + 1
. This causesjulia/src/jloptions.c
Line 624 in 11ce4d1
-1
and then we try to resizeARGS
to-1
here:julia/src/jloptions.c
Line 638 in 11ce4d1
I don't know if this is an acceptable fix, but feels like it should be safe on all systems.
edit: fixes #26761