From: Alejandro Colomar <alx.manpages@gmail.com>
To: Ian Abbott <abbotti@mev.co.uk>, Alejandro Colomar <alx@kernel.org>
Cc: linux-man@vger.kernel.org, GNU C Library <libc-alpha@sourceware.org>
Subject: Re: [PATCH] scanf.3: Do not mention the ERANGE error
Date: Fri, 9 Dec 2022 20:33:03 +0100 [thread overview]
Message-ID: <06f70d09-a258-7d6d-4a98-6a89ed761849@gmail.com> (raw)
In-Reply-To: <d1ecf57b-72cf-dbb4-3b4a-b19c7cdc93e9@mev.co.uk>
[-- Attachment #1.1: Type: text/plain, Size: 2570 bytes --]
Hi Ian,
On 12/9/22 20:28, Ian Abbott wrote:
> On 09/12/2022 18:59, Alejandro Colomar wrote:
>> On 12/8/22 13:34, Ian Abbott wrote:
>>> The `scanf()` function does not intentionally set `errno` to `ERANGE`.
>>> That is just a side effect of the code that it uses to perform
>>> conversions. It also does not work as reliably as indicated in the
>>> 'man' page when the target integer type is narrower than `long`.
>>> Typically (at least in glibc) for target integer types narrower than
>>> `long`, the number has to exceed the range of `long` (for signed
>>> conversions) or `unsigned long` (for unsigned conversions) for `errno`
>>> to be set to `ERANGE`.
>>>
>>> Documenting `ERANGE` in the ERRORS section kind of implies that
>>> `scanf()` should return `EOF` when an integer overflow is encountered,
>>> which it doesn't (and doing so would violate the C standard).
>>>
>>> Just remove any mention of the `ERANGE` error to avoid confusion.
>>>
>>> Fixes: 646af540e467 ("Add an ERRORS section documenting at least some of the
>>> errors that may occur for scanf().")
>>> Cc: Michael Kerrisk <mtk.manpages@gmail.com>
>>> Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
>>
>> I see. How about saying something like "it may also fail for any of any
>> errors that functions used to perform the conversions may fail"?
>
> It depends what you mean by "fail". These errors do not make scanf return EOF.
Just to clarify. Does scanf(3) _never_ fail (EOF) due to ERANGE? Or is it that
ERANGE sometimes makes it fail, sometimes not?
If it's the former, I agree with your patch. When a function hasn't reported
failure, errno is unspecified.
If it's the latter, I'd write something about it.
> Technically, the behavior is undefined if the result of the conversion cannot be
> represented in the object being assigned to by scanf. (In the case of glibc,
> that probably results in either the integer object being set to a truncated
> version of the input integer, or the integer object being set to a truncated
> version of LONG_MIN or LONG_MAX, depending on the actual number.)
Hmm, UB. Under UB, anything can change, so error reporting is already
unreliable. If EOF+ERANGE can _only_ happen under UB, I'd rather remove the
paragraph. Please confirm.
>
> Setting errno to 0 before calling scanf and expecting errno to have a meaningful
> value when scanf returns something other than EOF is bogus usage.
Yep, that's bogus.
Cheers,
Alex
--
<http://www.alejandro-colomar.es/>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2022-12-09 19:33 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20221208123454.13132-1-abbotti@mev.co.uk>
2022-12-09 18:59 ` Alejandro Colomar
2022-12-09 19:28 ` Ian Abbott
2022-12-09 19:33 ` Alejandro Colomar [this message]
2022-12-09 21:41 ` Zack Weinberg
2022-12-11 15:58 ` Alejandro Colomar
2022-12-11 16:03 ` Alejandro Colomar
2022-12-12 2:11 ` Zack Weinberg
2022-12-12 10:21 ` Alejandro Colomar
2022-12-14 2:13 ` Zack Weinberg
2022-12-14 10:47 ` Alejandro Colomar
2022-12-14 11:03 ` Ian Abbott
2022-12-29 6:42 ` Zack Weinberg
2022-12-29 6:39 ` Zack Weinberg
2022-12-29 10:47 ` Alejandro Colomar
2022-12-29 16:35 ` Zack Weinberg
2022-12-29 16:39 ` Alejandro Colomar
2022-12-12 15:22 ` Ian Abbott
2022-12-14 2:18 ` Zack Weinberg
2022-12-14 10:22 ` Ian Abbott
2022-12-14 10:39 ` Alejandro Colomar
2022-12-14 10:52 ` Ian Abbott
2022-12-14 11:23 ` Alejandro Colomar
2022-12-14 14:10 ` Ian Abbott
2022-12-14 16:38 ` Joseph Myers
2022-12-12 10:07 ` Ian Abbott
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=06f70d09-a258-7d6d-4a98-6a89ed761849@gmail.com \
--to=alx.manpages@gmail.com \
--cc=abbotti@mev.co.uk \
--cc=alx@kernel.org \
--cc=libc-alpha@sourceware.org \
--cc=linux-man@vger.kernel.org \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).