Re: Remaining dependency on setlocale() - Mailing list pgsql-hackers

From Robert Haas
Subject Re: Remaining dependency on setlocale()
Date
Msg-id CA+TgmobJh2tUXS5joNaY5Y6LTiWdFst4bWy3kYECSTvtvk_pBg@mail.gmail.com
Whole thread Raw
In response to Re: Remaining dependency on setlocale()  (Joe Conway <mail@joeconway.com>)
List pgsql-hackers
On Wed, Aug 7, 2024 at 9:42 AM Joe Conway <mail@joeconway.com> wrote:
> I guess in many/most places we use atoi we don't care, but maybe it
> matters for some?

I think we should move in the direction of replacing atoi() calls with
strtol() and actually checking for errors. In many places where use
atoi(), it's unlikely that the string would be anything but an
integer, so error checks are arguably unnecessary. A backup label file
isn't likely to say "START TIMELINE: potaytoes". On the other hand, if
it did say that, I'd prefer to get an error about potaytoes than have
it be treated as if it said "START TIMELINE: 0". And I've definitely
found missing error-checks over the years. For example, on pg14,
"pg_basebackup -Ft -Zmaximum -Dx" works as if you specified "-Z0"
because atoi("maximum") == 0. If we make a practice of checking
integer conversions for errors everywhere, we might avoid some such
silliness.

--
Robert Haas
EDB: http://www.enterprisedb.com



pgsql-hackers by date:

Previous
From: Nathan Bossart
Date:
Subject: Re: Remove dependence on integer wrapping
Next
From: Robert Haas
Date:
Subject: Re: pg_verifybackup: TAR format backup verification