pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Japin Li <japinli@hotmail.com>
Subject: [PATCH v1] Fix optind handling inconsistency in getopt_long() for missing argument
Date: Tue, 21 Jul 2026 17:49:02 +0800

Move optind++ and place = EMSG before the BADARG return in the long option
path to match short option behavior and ensure consistent state.
---
 src/port/getopt_long.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

inline patch 1: src/port/getopt_long.c (+3/-3 lines) download inline-1.patchdiff --git a/src/port/getopt_long.c b/src/port/getopt_long.c index 20953db9db1..a488a647889 100644 --- a/src/port/getopt_long.c +++ b/src/port/getopt_long.c @@ -145,6 +145,9 @@ retry: } else { + place = EMSG; + optind++; + if (optstring[0] == ':') return BADARG; @@ -153,9 +156,6 @@ retry: "%s: option requires an argument -- %s\n", argv[0], place); - place = EMSG; - optind++; - if (has_arg == required_argument) return BADCH; optarg = NULL; -- 2.53.0
--=-=-=--

Message-ID: <no-message-id-1008945@localhost>
Permalink:  ../no-message-id-1008945@localhost/
Also on:    postgresql.org/message-id/no-message-id-1008945@localhost

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: japinli@hotmail.com
  Subject: Re: [PATCH v1] Fix optind handling inconsistency in getopt_long() for missing argument
  In-Reply-To: <no-message-id-1008945@localhost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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