Ping: [PATCH] inttypes.h: strtoi(), strtou(): Prefer reporting ERANGE over ENOTSUP
Alejandro Colomar
alx at kernel.org
Thu Feb 8 14:50:02 UTC 2024
Hi Guillem!
On Wed, Jan 24, 2024 at 07:16:23PM +0100, Alejandro Colomar wrote:
> If both ERANGE and ENOTSUP conditions happen, ENOTSUP can be tested
> secondarily as `*end != '\0'`. However, there's no secondary mechanism
> to test ERANGE. Thus, it is important to report ERANGE, and let the
> user check *end if necessary.
>
> Most NetBSD and Debian existing code assumed that strtoi/u() reported
> ERANGE with preference, and so there were several bugs caused by the old
> behavior. In fact, there was only one place where it was the other way
> around: the implementation of strtonum(). This change of behavior fixes
> several bugs in various code bases.
>
> The implementation of strtonum() has been adjusted to keep its behavior
> unmodified.
>
> NetBSD has changed the behavior of their implementation after my bug
> report, so this patch makes our API compatible with theirs.
NetBSD's git mirror now contains the patches:
$ git show f1987b28c87e --stat \
| grep '|' \
| awk '{print $1}' \
| xargs git log --oneline -- \
| awk '{print $1}' \
| head -n2 \
| xargs git show --stat;
commit 0c834cb5237e0081f73e7baa8eb3367b57fdb80c
Author: christos <christos at NetBSD.org>
Date: Sat Jan 20 16:45:07 2024 +0000
generate strtou.3 from strtoi.3, grammar police
lib/libc/stdlib/Makefile.inc | 8 +-
lib/libc/stdlib/strtoi.3 | 4 +-
lib/libc/stdlib/strtou.3 | 240 -------------------------------------------
3 files changed, 9 insertions(+), 243 deletions(-)
commit f1987b28c87ee37690268b93ba1b11ed8d571305
Author: christos <christos at NetBSD.org>
Date: Sat Jan 20 16:13:39 2024 +0000
PR/57828: Alejandro Colomar: Prioritize test for ERANGE before testing for
fully consuming the string. Adjust strtonum(3) to behave as before. Document
the order of the tests and sync the man pages (I should really autogenerate
one of the two man pages...)
common/lib/libc/stdlib/_strtoi.h | 18 +++++++++---------
lib/libc/stdlib/strtoi.3 | 20 +++++++++++++-------
lib/libc/stdlib/strtonum.c | 33 ++++++++++++++++++++-------------
lib/libc/stdlib/strtou.3 | 18 ++++++++++++------
4 files changed, 54 insertions(+), 35 deletions(-)
Have a lovely day,
Alex
>
> Link: <https://lists.sr.ht/~hallyn/shadow/%3CZZoQDms6Sv6e5SPE%40debian%3E>
> Link: <https://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=57828>
> Cc: Guillem Jover <guillem at hadrons.org>
> Cc: Thorsten Glaser <tg at mirbsd.de>
> Cc: christos <christos at netbsd.org>
> Cc: Taylor R Campbell <riastradh at netbsd.org>
> Cc: Mouse <mouse at Rodents-Montreal.ORG>
> Cc: roy <roy at netbsd.org>
> Cc: <tech-userlevel at netbsd.org>
> Signed-off-by: Alejandro Colomar <alx at kernel.org>
> ---
> man/strtoi.3bsd | 4 +++-
> man/strtou.3bsd | 4 +++-
> src/strtoi.c | 14 ++++++--------
> src/strtonum.c | 6 ++++--
> src/strtou.c | 14 ++++++--------
> 5 files changed, 22 insertions(+), 20 deletions(-)
--
<https://www.alejandro-colomar.es/>
Looking for a remote C programming job at the moment.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/libbsd/attachments/20240208/ef48c241/attachment.sig>
More information about the libbsd
mailing list