From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org, Alejandro Colomar <alx@kernel.org>
Cc: "Paul Eggert" <eggert@cs.ucla.edu>,
"Đoàn Trần Công Danh" <congdanhqx@gmail.com>,
"Eli Schwartz" <eschwartz93@gmail.com>,
"Sam James" <sam@gentoo.org>, "Serge Hallyn" <serge@hallyn.com>,
"Iker Pedrosa" <ipedrosa@redhat.com>,
"Andrew J. Hesford" <ajh@sideband.org>,
"Michael Vetter" <jubalh@iodoru.org>,
liba2i@lists.linux.dev
Subject: Re: [PATCH v1] xstrtol: Remove dead code
Date: Thu, 18 Jul 2024 23:09:40 +0200 [thread overview]
Message-ID: <8009158.qOBuL9xsDt@nimes> (raw)
In-Reply-To: <20240718203147.47143-2-alx@kernel.org>
Hi Alejandro,
> strtol(3) has a limited set of possible states:
> ...
> The condition '*endp != s && errno != 0 && errno != ERANGE' is
> unreachable. The only errno possible if '*endp != s' is ERANGE.
Such a statement can be true if you look at the standards (ISO C, POSIX).
However, there's a difference between what the standards say and what the
systems actually do. The Gnulib documentation contains thousands of examples
of such differences.
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 implementations
of strtod() do use malloc().
So, what you call "dead code", I call "defensive programming". I would not
like to apply this patch.
Bruno
[1] https://www.gnu.org/software/gnulib/manual/html_node/getlogin_005fr.html
next prev parent reply other threads:[~2024-07-18 21:21 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-18 20:33 [PATCH v1] xstrtol: Remove dead code Alejandro Colomar
2024-07-18 21:09 ` Bruno Haible [this message]
2024-07-18 21:25 ` Alejandro Colomar
2024-07-18 21:33 ` Andrew J. Hesford
2024-07-18 22:14 ` Alejandro Colomar
2024-07-18 23:32 ` Alejandro Colomar
2024-07-19 17:13 ` Bruno Haible
2024-07-18 22:34 ` Bruno Haible
2024-07-18 23:21 ` Alejandro Colomar
2024-07-19 16:54 ` Bruno Haible
2024-07-19 18:15 ` Alejandro Colomar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8009158.qOBuL9xsDt@nimes \
--to=bruno@clisp.org \
--cc=ajh@sideband.org \
--cc=alx@kernel.org \
--cc=bug-gnulib@gnu.org \
--cc=congdanhqx@gmail.com \
--cc=eggert@cs.ucla.edu \
--cc=eschwartz93@gmail.com \
--cc=ipedrosa@redhat.com \
--cc=jubalh@iodoru.org \
--cc=liba2i@lists.linux.dev \
--cc=sam@gentoo.org \
--cc=serge@hallyn.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox