Unify parsing logic for command-line integer options
authorMichael Paquier <michael@paquier.xyz>
Sat, 24 Jul 2021 09:35:03 +0000 (18:35 +0900)
committerMichael Paquier <michael@paquier.xyz>
Sat, 24 Jul 2021 09:35:03 +0000 (18:35 +0900)
commit6f164e6d17616a157ea5d9e34dbb1b211c080c41
tree211dc850cd3deb995555efd66b75899c2b37ae7a
parent6beb38cfc9ddd4cd3d2eb5402981ebdd69a618b4
Unify parsing logic for command-line integer options

Most of the integer options for command-line binaries now make use of a
single routine able to do the job, fixing issues with the detection of
sloppy values caused for example by the use of atoi(), that fails on
strings beginning with numerical characters with junk trailing
characters.

This commit cuts down the number of strings requiring translation by 26
per my count, switching the code to have two error types for invalid and
out-of-range values instead.

Much more could be done here, with float or even int64 options, but
int32 was the most appealing case as it is possible to rely on strtol()
to do the job reliably.  Note that there are some exceptions for now,
like pg_ctl or pg_upgrade that use their own logging logic.  A couple of
negative TAP tests required some adjustments for the new errors
generated.

pg_dump and pg_restore tracked the maximum number of parallel jobs
within the option parsing.  The code is refactored a bit to track that
in the code dedicated to parallelism instead.

Author: Kyotaro Horiguchi, Michael Paquier
Reviewed-by: David Rowley, Álvaro Herrera
Discussion: https://postgr.es/m/CALj2ACXqdG9WhqVoJ9zYf-iZt7sgK7Szv5USs=he6NnWQ2ofTA@mail.gmail.com
17 files changed:
src/bin/pg_amcheck/pg_amcheck.c
src/bin/pg_basebackup/pg_basebackup.c
src/bin/pg_basebackup/pg_receivewal.c
src/bin/pg_basebackup/pg_recvlogical.c
src/bin/pg_checksums/Makefile
src/bin/pg_checksums/pg_checksums.c
src/bin/pg_dump/parallel.h
src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/pg_restore.c
src/bin/pg_dump/t/001_basic.pl
src/bin/pgbench/pgbench.c
src/bin/pgbench/t/002_pgbench_no_server.pl
src/bin/scripts/createuser.c
src/bin/scripts/reindexdb.c
src/bin/scripts/vacuumdb.c
src/fe_utils/option_utils.c
src/include/fe_utils/option_utils.h