Skip trailing whitespaces when parsing integer options
strtoint(), via strtol(), would skip leading whitespaces but the same rule was not applied for trailing whitespaces, leading to an inconsistent behavior. Some tests are changed to cover more this area. Author: Michael Paquier Reviewed-by: Kyotaro Horiguchi Discussion: https://postgr.es/m/YP5Pv0d13Ct+03ve@paquier.xyz
This commit is contained in:
parent
21b3aa9c8f
commit
f7a9a3d4b2
@ -88,6 +88,8 @@ SKIP:
|
|||||||
$primary->psql('postgres',
|
$primary->psql('postgres',
|
||||||
'INSERT INTO test_table VALUES (generate_series(100,200));');
|
'INSERT INTO test_table VALUES (generate_series(100,200));');
|
||||||
|
|
||||||
|
# Note the trailing whitespace after the value of --compress, that is
|
||||||
|
# a valid value.
|
||||||
$primary->command_ok(
|
$primary->command_ok(
|
||||||
[
|
[
|
||||||
'pg_receivewal', '-D', $stream_dir, '--verbose',
|
'pg_receivewal', '-D', $stream_dir, '--verbose',
|
||||||
|
@ -101,6 +101,7 @@ command_fails_like(
|
|||||||
qr/\Qpg_dump: error: parallel backup only supported by the directory format\E/,
|
qr/\Qpg_dump: error: parallel backup only supported by the directory format\E/,
|
||||||
'pg_dump: parallel backup only supported by the directory format');
|
'pg_dump: parallel backup only supported by the directory format');
|
||||||
|
|
||||||
|
# Note the trailing whitespace for the value of --jobs, that is valid.
|
||||||
command_fails_like(
|
command_fails_like(
|
||||||
[ 'pg_dump', '-j', '-1 ' ],
|
[ 'pg_dump', '-j', '-1 ' ],
|
||||||
qr/\Qpg_dump: error: -j\/--jobs must be in range\E/,
|
qr/\Qpg_dump: error: -j\/--jobs must be in range\E/,
|
||||||
|
@ -57,7 +57,14 @@ option_parse_int(const char *optarg, const char *optname,
|
|||||||
errno = 0;
|
errno = 0;
|
||||||
val = strtoint(optarg, &endptr, 10);
|
val = strtoint(optarg, &endptr, 10);
|
||||||
|
|
||||||
if (*endptr)
|
/*
|
||||||
|
* Skip any trailing whitespace; if anything but whitespace remains before
|
||||||
|
* the terminating character, fail.
|
||||||
|
*/
|
||||||
|
while (*endptr != '\0' && isspace((unsigned char) *endptr))
|
||||||
|
endptr++;
|
||||||
|
|
||||||
|
if (*endptr != '\0')
|
||||||
{
|
{
|
||||||
pg_log_error("invalid value \"%s\" for option %s",
|
pg_log_error("invalid value \"%s\" for option %s",
|
||||||
optarg, optname);
|
optarg, optname);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user