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 <chris...@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 <chris...@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 <guil...@hadrons.org>
> Cc: Thorsten Glaser <t...@mirbsd.de>
> Cc: christos <chris...@netbsd.org>
> Cc: Taylor R Campbell <riastr...@netbsd.org>
> Cc: Mouse <mo...@rodents-montreal.org>
> Cc: roy <r...@netbsd.org>
> Cc: <tech-userlevel@netbsd.org>
> Signed-off-by: Alejandro Colomar <a...@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.

Attachment: signature.asc
Description: PGP signature

Reply via email to