From: Rich Felker Date: Wed, 21 Jan 2015 18:16:15 +0000 (-0500) Subject: always set optarg in getopt_long X-Git-Tag: v1.1.7~78 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=e8e4e56a8ce1f3d7e4a027ff5478f2f8ea70c46b;p=oweals%2Fmusl.git always set optarg in getopt_long the standard getopt does not touch optarg unless processing an option with an argument. however, programs using the GNU getopt API, which we attempt to provide in getopt_long, expect optarg to be a null pointer after processing an option without an argument. before argument permutation support was added, such programs typically detected its absence and used their own replacement getopt_long, masking the discrepency in behavior. --- diff --git a/src/misc/getopt_long.c b/src/misc/getopt_long.c index ffbcd423..bee77f43 100644 --- a/src/misc/getopt_long.c +++ b/src/misc/getopt_long.c @@ -51,7 +51,7 @@ static int __getopt_long(int argc, char *const *argv, const char *optstring, con static int __getopt_long_core(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly) { - + optarg = 0; if (longopts && argv[optind][0] == '-' && ((longonly && argv[optind][1]) || (argv[optind][1] == '-' && argv[optind][2])))