> On Nov 27, 2026, at 02:30, Raja Sai pranav <[email protected]> wrote:
>
> Hi,
>
> Two integer options are still read with atoi(), so a non-numeric value
> silently becomes 0:
>
> pg_createsubscriber --recovery-timeout=abc timeout disabled (0 = none)
> pgbench --max-tries=abc unlimited tries
>
> pg_createsubscriber also accepts negative timeouts. The other client
> programs moved to option_parse_int() in 2021 [1]. pg_ctl was left out
> on purpose there (Windows event logging), but pg_createsubscriber did not
> exist yet and uses the common logging.
>
> The attached patch uses option_parse_int() for both, still allowing 0.
> For --max-tries the error for a negative value changes from "invalid
> number of maximum tries" to the usual "must be in range" message.
> Tests are added in
> https://www.google.com/url?q=http://040_pg_createsubscriber.pl&source=gmail&ust=1795804224713000&sa=E
> and
> https://www.google.com/url?q=http://002_pgbench_no_server.pl&source=gmail&ust=1795804224713000&sa=E.
> They fail without the change and pass with it.
>
> [1]
> https://www.google.com/url?q=https://postgr.es/m/calj2acxqdg9whqvoj9zyf-izt7sgk7szv5uss%[email protected]&source=gmail&ust=1795804224713000&sa=E
>
> Regards,
> Sai Pranav
> <v1-0001-Use-option_parse_int-for-two-more-integer-options.patch>
I think the fix is reasonable. In pgbench.c, case 11 (--partitions) already
uses option_parse_int(), so switching case 14 (--max-tries) from atoi() to
option_parse_int() makes the code more consistent.
I searched for atoi() and found similar uses in pg_ctl and pg_upgrade. As
commit 6f164e6d176, which introduced option_parse_int(), intentionally excluded
those two programs, I’d leave them untouched.
So, v1 looks good to me.
BTW, while testing this patch, I found that option_parse_int() itself also has
a bug. After calling strtoint(), it skips trailing whitespace without first
checking parsing error. So if we pass a single space as --max-tries=' ',
pgbench treats it as 0, just as it treated “abc” as you reported. But that’s a
separate issue, and I’ll start a new thread about it.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/