Re: [PATCH] scanf.3: Do not mention the ERANGE error

Eric Biggers
2023-01-20T04:36:23Z

Hi Alejandro,

On Mon, Dec 12, 2022 at 12:33:08PM +0100, Alejandro Colomar wrote:
> > 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 applied the patch; thanks! And also applied another one explicitly
> marking all those numeric conversion specifiers as deprecated:
>
> <https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit/?id=a15d34326c581eab107bf05782cc60d8ebdcad69>
>
> Cheers,
>

This is commonly used functionality with no replacement suggested. Should it
really be deprecated? Is the undefined behavior here a real world issue
anywhere, or is this just a theoretical issue based on interpretation of the C
standard? Perhaps instead of a deprecation, this just deserves a mention in the
BUGS section of the man page, and a request to the C standard committee to fix
the text in the standard to make the behavior defined?

I'll note that memcpy() is not deprecated, even though the C standard has a bug
where 'memcpy(dst, src, 0)' is undefined if either pointer is NULL. That's a
very similar sort of issue. The fix, of course, is for implementations to
ignore the defective standard and make the behavior defined...

- Eric