pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
[PATCH v2 2/2] Fix optind handling inconsistency in getopt_long() for missing argument
1+ messages / 1 participants
[nested] [flat]

* [PATCH v2 2/2] Fix optind handling inconsistency in getopt_long() for missing argument
@ 2026-07-22 03:59 Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 1+ messages in thread

From: Japin Li @ 2026-07-22 03:59 UTC (permalink / raw)

In the long option error path for a missing required argument, the code
previously checked optstring[0] == ':' and returned BADARG immediately
without incrementing optind and setting place = EMSG.  This left optind
and place in an inconsistent state compared to the short option path,
where these updates are performed before the check and return.
---
 src/port/getopt_long.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

inline patch 1: src/port/getopt_long.c (+4/-1 lines) download inline-1.patchdiff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 20953db9db1..2e869fed58b 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -145,8 +145,12 @@ retry: } else { + optind++; if (optstring[0] == ':') + { + place = EMSG; return BADARG; + } if (opterr && has_arg == required_argument) fprintf(stderr, @@ -154,7 +158,6 @@ retry: argv[0], place); place = EMSG; - optind++; if (has_arg == required_argument) return BADCH; -- 2.53.0
--=-=-=-- ^ permalink raw reply [nested|flat] 1+ messages in thread


only message in thread

Thread overview: 1+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-07-22 03:59 [PATCH v2 2/2] Fix optind handling inconsistency in getopt_long() for missing argument Japin Li <japinli@hotmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox