Re: [PATCH v1] xstrtol: Remove dead code

"Andrew J. Hesford" <[email protected]> Thu, 18 Jul 2024 17:33:00 -0400
Newsgroups dev.linux.lists.liba2i
Message-ID <[email protected]>
Stop tagging me in your submissions. I have no involvement in any of this ac=
tivity.
--=20
Andrew J. Hesford
[email protected]
[Mobile communication]

> On Jul 18, 2024, at 5:25=E2=80=AFPM, Alejandro Colomar <[email protected]> wr=
ote:
>=20
> =EF=BB=BFOn Thu, Jul 18, 2024 at 11:09:40PM GMT, Bruno Haible wrote:
>> Hi Alejandro,
>=20
> Hi Bruno,
>=20
>>> strtol(3) has a limited set of possible states:
>>> ...
>>> The condition '*endp !=3D s && errno !=3D 0 && errno !=3D ERANGE' is
>>> unreachable.  The only errno possible if '*endp !=3D s' is ERANGE.
>>=20
>> Such a statement can be true if you look at the standards (ISO C, POSIX).=

>>=20
>> However, there's a difference between what the standards say and what the=

>> systems actually do. The Gnulib documentation contains thousands of examp=
les
>> of such differences.
>>=20
>> Gnulib therefore (almost) never assumes that there are no possible errno
>> values besides the ones listed in the standards.
>>  - Some systems return "wrong" errno values. Example: [1]
>>  - Some systems fail with ENOMEM when memory is tight. Who says that
>>    an implementation of strtol() cannot use malloc() ? Some implementatio=
ns
>>    of strtod() do use malloc().
>>=20
>> So, what you call "dead code", I call "defensive programming". I would no=
t
>> like to apply this patch.
>=20
> Makes sense.  I think we should document that possibility in the manual
> page.  Maybe say that other errno values are possible in some systems?
> Otherwise, it's already a hell of a function to take care of, and most
> uses don't handle that possibility at the moment.  (Yet more reasons to
> use a wrapper that returns -1 & sets errno on error, as the rest of
> libc.)
>=20
> Would you send a patch?  (I'd write it myself, but you probably can
> provide more info in the commit message.)
>=20
> Have a lovely night!
> Alex
>=20
>>=20
>> Bruno
>>=20
>> [1] https://www.gnu.org/software/gnulib/manual/html_node/getlogin_005fr.h=
tml
>>=20
>>=20
>>=20
>=20
> --
> <https://www.alejandro-colomar.es/>
> <signature.asc>