From ef9c12b157a50d63e8a8eb710c013d16c2cea319 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 21 Mar 2023 10:05:33 +0900 Subject: tree-wide: reset optind to 0 when GNU extensions in optstring are used Otherwise, if getopt() and friends are used before parse_argv(), then the GNU extensions may be ignored. This should not change any behavior at least now, as we usually use getopt_long() only once per invocation. But in the next commit, getopt_long() will be used for other arrays, hence this change will become necessary. --- src/ask-password/ask-password.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/ask-password') diff --git a/src/ask-password/ask-password.c b/src/ask-password/ask-password.c index f161e65973..e9c09b7825 100644 --- a/src/ask-password/ask-password.c +++ b/src/ask-password/ask-password.c @@ -108,6 +108,10 @@ static int parse_argv(int argc, char *argv[]) { /* Note the asymmetry: the long option --echo= allows an optional argument, the short option does * not. */ + + /* Resetting to 0 forces the invocation of an internal initialization routine of getopt_long() + * that checks for GNU extensions in optstring ('-' or '+' at the beginning). */ + optind = 0; while ((c = getopt_long(argc, argv, "+hen", options, NULL)) >= 0) switch (c) { -- cgit v1.2.1