Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf7a9a3d

Browse files
committed
Skip trailing whitespaces when parsing integer options
strtoint(), via strtol(), would skip leading whitespaces but the samerule was not applied for trailing whitespaces, leading to aninconsistent behavior. Some tests are changed to cover more this area.Author: Michael PaquierReviewed-by: Kyotaro HoriguchiDiscussion:https://postgr.es/m/YP5Pv0d13Ct+03ve@paquier.xyz
1 parent21b3aa9 commitf7a9a3d

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

‎src/bin/pg_basebackup/t/020_pg_receivewal.pl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,12 @@
8888
$primary->psql('postgres',
8989
'INSERT INTO test_table VALUES (generate_series(100,200));');
9090

91+
# Note the trailing whitespace after the value of --compress, that is
92+
# a valid value.
9193
$primary->command_ok(
9294
[
9395
'pg_receivewal','-D',$stream_dir,'--verbose',
94-
'--endpos',$nextlsn,'--compress','1'
96+
'--endpos',$nextlsn,'--compress','1'
9597
],
9698
"streaming some WAL using ZLIB compression");
9799

‎src/bin/pg_dump/t/001_basic.pl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@
101101
qr/\Qpg_dump: error: parallel backup only supported by the directory format\E/,
102102
'pg_dump: parallel backup only supported by the directory format');
103103

104+
# Note the trailing whitespace for the value of --jobs, that is valid.
104105
command_fails_like(
105-
['pg_dump','-j','-1' ],
106+
['pg_dump','-j','-1' ],
106107
qr/\Qpg_dump: error: -j\/--jobs must be in range\E/,
107108
'pg_dump: -j/--jobs must be in range');
108109

‎src/fe_utils/option_utils.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,14 @@ option_parse_int(const char *optarg, const char *optname,
5757
errno=0;
5858
val=strtoint(optarg,&endptr,10);
5959

60-
if (*endptr)
60+
/*
61+
* Skip any trailing whitespace; if anything but whitespace remains before
62+
* the terminating character, fail.
63+
*/
64+
while (*endptr!='\0'&&isspace((unsignedchar)*endptr))
65+
endptr++;
66+
67+
if (*endptr!='\0')
6168
{
6269
pg_log_error("invalid value \"%s\" for option %s",
6370
optarg,optname);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp