Re: [PATCH] Fix missing argument handling in psql getopt

2019-08-25 Thread Quentin Rameau
> I've pushed your original patch (with some comment-tweaking). > It seems unlikely to break anything. Thanks!

Re: [PATCH] Fix missing argument handling in psql getopt

2019-08-25 Thread Tom Lane
Quentin Rameau writes: > Another better way, I think, to fix this is to check for optopt > instead, which would be set to the option which caused the error, which > if empty means there isn't an error. Meh. We don't use optopt at all today, and I don't especially want to start doing so. A patch

Re: [PATCH] Fix missing argument handling in psql getopt

2019-08-25 Thread Quentin Rameau
> Another better way, I think, to fix this is to check for optopt > instead, which would be set to the option which caused the error, which > if empty means there isn't an error. > > Patch attached. Actually OpenBSD seems to set optopt to '?' by default, so the updated attached patch ensure we st

Re: [PATCH] Fix missing argument handling in psql getopt

2019-08-25 Thread Quentin Rameau
> > “If the option was the last character in the string pointed to by an > > element of argv, then optarg shall contain the next element of argv, > > and optind shall be incremented by 2. If the resulting value of optind > > is greater than argc, this indicates a missing option-argument, and > > ge

Re: [PATCH] Fix missing argument handling in psql getopt

2019-08-25 Thread Tom Lane
Quentin Rameau writes: >> Um ... so how would control get there with optind too large? > That's from the getopt specification[0]: > “If the option was the last character in the string pointed to by an > element of argv, then optarg shall contain the next element of argv, > and optind shall be in

Re: [PATCH] Fix missing argument handling in psql getopt

2019-08-25 Thread Quentin Rameau
> > Um ... so how would control get there with optind too large? Sorry, I missed the simple explanation for that: As option 'h' is missing an argument, getopt(_long) returns the character '?' which is switched on through variable c, and the program jumps to the '?' case handling.

Re: [PATCH] Fix missing argument handling in psql getopt

2019-08-25 Thread Quentin Rameau
Hello Tom, > > When passing an argument option with a missing argument, strcmp > > would be called with the argv terminating NULL. > > Um ... so how would control get there with optind too large? That's from the getopt specification[0]: “If the option was the last character in the string poin

Re: [PATCH] Fix missing argument handling in psql getopt

2019-08-25 Thread Tom Lane
Quentin Rameau writes: > When passing an argument option with a missing argument, strcmp would > be called with the argv terminating NULL. Um ... so how would control get there with optind too large? What test case/platform are you considering? (There really shouldn't be *any* case where getopt