Re: [PATCH] lib/xstrtol.c: Fix xstrtol() on EINVAL (invalid base)

2024-08-05 Thread Bruno Haible
> 2024-07-29 Bruno Haible > > xstrtol, xstrtoll tests: Avoid test failure after 2024-07-25 change. > * tests/test-xstrtol.c (main): Update expected test results. I had tested this in a small testdir. But in a testdir of all of gnulib, it still fails on musl libc, macOS, NetBSD, Ope

Re: [PATCH] lib/xstrtol.c: Fix xstrtol() on EINVAL (invalid base)

2024-07-29 Thread Bruno Haible
Paul Eggert wrote: > I installed the attached patch to go back to the old way of doing things, > ... > I didn't adjust the recently-added Gnulib test cases even though they're > testing what is now documented to be undefined behavior, as they still > pass on the FreeBSD and Ubuntu platforms that

Re: [PATCH] lib/xstrtol.c: Fix xstrtol() on EINVAL (invalid base)

2024-07-26 Thread Bruno Haible
Paul Eggert wrote: > I installed the attached patch Thanks. Stating which conditions produce undefined behaviour goes a long way at avoiding programmer pitfalls. > It's OK for > behavior to be undefined when the base is bad, just as it's OK for it to > be undefined if the string is bad (e.g., w

Re: [PATCH] lib/xstrtol.c: Fix xstrtol() on EINVAL (invalid base)

2024-07-25 Thread Paul Eggert
On 2024-07-25 14:27, Bruno Haible wrote: I have a hard time understanding the point and purpose of what you are saying: - In you removed the validation of 'base', saying: "strtol can support base 1 as an extensi

Re: [PATCH] lib/xstrtol.c: Fix xstrtol() on EINVAL (invalid base)

2024-07-25 Thread Bruno Haible
> xstrtol, xstrtoll tests: Test behaviour for an invalid base. The CI reported a failure on FreeBSD (not on NetBSD, not on OpenBSD). This patch makes the test succeed. 2024-07-25 Bruno Haible xstrtol, xstrtoll tests: Avoid test failure on FreeBSD. * tests/test-xstrtol.

Re: [PATCH] lib/xstrtol.c: Fix xstrtol() on EINVAL (invalid base)

2024-07-25 Thread Bruno Haible
Hi Paul, > > +strtol_error s_err = __xstrtol (input, &endp, -1, &val, "k"); > > +ASSERT (s_err == LONGINT_INVALID); > > +ASSERT (endp == NULL); > > +ASSERT (val == -17); > > This isn't a valid test case. If the base is -1, the underlying strtol > can support any b

Re: [PATCH] lib/xstrtol.c: Fix xstrtol() on EINVAL (invalid base)

2024-07-25 Thread Collin Funk
Paul Eggert writes: > If the documentation doesn't make it sufficiently clear that the > behavior is not fully specified with an invalid base, we can do that. > But let's not waste time testing corner cases that don't matter. +1. I don't see why anyone would ever pass -1 as a base to strtol. Usu

Re: [PATCH] lib/xstrtol.c: Fix xstrtol() on EINVAL (invalid base)

2024-07-25 Thread Paul Eggert
On 2024-07-25 13:11, Bruno Haible wrote: +strtol_error s_err = __xstrtol (input, &endp, -1, &val, "k"); +ASSERT (s_err == LONGINT_INVALID); +ASSERT (endp == NULL); +ASSERT (val == -17); This isn't a valid test case. If the base is -1, the underlying strtol can s

Re: [PATCH] lib/xstrtol.c: Fix xstrtol() on EINVAL (invalid base)

2024-07-25 Thread Bruno Haible
Alejandro Colomar wrote: > > > Assuming that the string matches a valid suffix, it'd succeed, but the > > > call should have failed early. > > > > No, because that code is dealing with the case where the number's text is > > missing. And if the number's text is missing it doesn't matter what the b

Re: [PATCH] lib/xstrtol.c: Fix xstrtol() on EINVAL (invalid base)

2024-07-25 Thread Paul Eggert
On 2024-07-25 09:39, Alejandro Colomar wrote: So, we have arrived there, tmp is 1, and the suffix is "k", so it will be multiplied by 1000. That's the expected behavior. I passed a base of -1. Fine, so don't do that. When you use base -1, it doesn't matter whether the behavior differs on

Re: [PATCH] lib/xstrtol.c: Fix xstrtol() on EINVAL (invalid base)

2024-07-25 Thread Alejandro Colomar
On Thu, Jul 25, 2024 at 06:39:53PM GMT, Alejandro Colomar wrote: > Hi Paul, > > On Thu, Jul 25, 2024 at 07:55:15AM GMT, Paul Eggert wrote: > > On 2024-07-25 02:27, Alejandro Colomar wrote: > > > - tmp = 1; > > > > > > We will multiply the base by 1, even if it wasn't in the string. > > > > I

Re: [PATCH] lib/xstrtol.c: Fix xstrtol() on EINVAL (invalid base)

2024-07-25 Thread Alejandro Colomar
Hi Paul, On Thu, Jul 25, 2024 at 07:55:15AM GMT, Paul Eggert wrote: > On 2024-07-25 02:27, Alejandro Colomar wrote: > > - tmp = 1; > > > > We will multiply the base by 1, even if it wasn't in the string. > > I don't see that. There's no multiplication of BASE by 1 in "tmp = 1;". D'oh, sorr

Re: [PATCH] lib/xstrtol.c: Fix xstrtol() on EINVAL (invalid base)

2024-07-25 Thread Paul Eggert
On 2024-07-25 02:27, Alejandro Colomar wrote: - tmp = 1; We will multiply the base by 1, even if it wasn't in the string. I don't see that. There's no multiplication of BASE by 1 in "tmp = 1;". I don't understand too much the rest of xstrtol(), but I think it will successfully pars

Re: [PATCH] lib/xstrtol.c: Fix xstrtol() on EINVAL (invalid base)

2024-07-25 Thread Alejandro Colomar
Hi Paul, On Wed, Jul 24, 2024 at 05:09:09PM GMT, Paul Eggert wrote: > On 2024-07-24 14:07, Alejandro Colomar wrote: > > > I forgot to reply to the last part: "Why isn't that [current gnulib] > > good enough? > > > > With an implementation of strtol(3) that does what I wrote above, the > > test `

Re: [PATCH] lib/xstrtol.c: Fix xstrtol() on EINVAL (invalid base)

2024-07-24 Thread Paul Eggert
On 2024-07-24 14:07, Alejandro Colomar wrote: I forgot to reply to the last part: "Why isn't that [current gnulib] good enough? With an implementation of strtol(3) that does what I wrote above, the test `if (!t_ptr)` isn't true, so we go to `if (*p == nptr && (errno == 0 || errno == EINVAL))`,

Re: [PATCH] lib/xstrtol.c: Fix xstrtol() on EINVAL (invalid base)

2024-07-24 Thread Alejandro Colomar
On Wed, Jul 24, 2024 at 10:54:52PM GMT, Alejandro Colomar wrote: > Hi Paul, > > On Wed, Jul 24, 2024 at 01:11:33PM GMT, Paul Eggert wrote: > > On 2024-07-24 12:27, Alejandro Colomar wrote: > > > POSIX leaves the value of *endptr unspecified if the base is invalid; > > > it is not unmodified. > >

Re: [PATCH] lib/xstrtol.c: Fix xstrtol() on EINVAL (invalid base)

2024-07-24 Thread Alejandro Colomar
Hi Paul, On Wed, Jul 24, 2024 at 01:11:33PM GMT, Paul Eggert wrote: > On 2024-07-24 12:27, Alejandro Colomar wrote: > > POSIX leaves the value of *endptr unspecified if the base is invalid; > > it is not unmodified. > > Fine, we can let xstrtol do the same. > > > That, combined with the fact tha

Re: [PATCH] lib/xstrtol.c: Fix xstrtol() on EINVAL (invalid base)

2024-07-24 Thread Paul Eggert
On 2024-07-24 12:27, Alejandro Colomar wrote: POSIX leaves the value of *endptr unspecified if the base is invalid; it is not unmodified. Fine, we can let xstrtol do the same. That, combined with the fact that POSIX allows implementations of strtol(3) to set EINVAL when no digits are found,

Re: [PATCH] lib/xstrtol.c: Fix xstrtol() on EINVAL (invalid base)

2024-07-24 Thread Alejandro Colomar
On Wed, Jul 24, 2024 at 09:27:14PM GMT, Alejandro Colomar wrote: > POSIX leaves the value of *endptr unspecified if the base is invalid; > it is not unmodified. > > glibc and musl libc leave the object unmodified. However, the BSDs and > Bionic libc modify it to be nptr. > > That, combined with

[PATCH] lib/xstrtol.c: Fix xstrtol() on EINVAL (invalid base)

2024-07-24 Thread Alejandro Colomar
POSIX leaves the value of *endptr unspecified if the base is invalid; it is not unmodified. glibc and musl libc leave the object unmodified. However, the BSDs and Bionic libc modify it to be nptr. That, combined with the fact that POSIX allows implementations of strtol(3) to set EINVAL when no d