strtou(3) handling of negative input
Alejandro Colomar <[email protected]> Thu, 20 Mar 2025 00:30:36 +0100
| Newsgroups | dev.linux.lists.liba2i |
|---|---|
| Message-ID | <4522a56argkcmsspyc7ukrk5vzj2zyjco2xk7hgdwmwszn6hbn@2vquzrpsbq3b> |
--xmevghi4tmk2s4kb Content-Type: text/plain; protected-headers=v1; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable From: Alejandro Colomar <[email protected]> To: Bruno Haible <[email protected]> Cc: [email protected], [email protected], [email protected], [email protected], christos <[email protected]>, =?utf-8?B?xJBvw6BuIFRy4bqnbiBDw7RuZw==?= Danh <[email protected]>, Paul Eggert <[email protected]>, Eli Schwartz <[email protected]>, Guillem Jover <[email protected]>, Iker Pedrosa <[email protected]>, Michael Vetter <[email protected]>, Robert Elz <[email protected]>, [email protected], Sam James <[email protected]>, "Serge E. Hallyn" <[email protected]> Subject: strtou(3) handling of negative input References: <mgcfwxfmv3kpfnkkf6uj63kx5tdzl64p2zg2us4ntsu6q5xkwj@k52z5yyiywoo> <3237498.fEcJ0Lxnt5@nimes> <jx4664ishtl34eg2npdrv5fkfdiczqnlq3vjuacjrupjvh377x@gddcftzgwmfq> <4085563.2iPT33SAM4@nimes> <x34jdlyb6gf6asojjhzwpol5schyz4llk2ebrtzpb7ryje52u6@smbvzpoqcf6v> MIME-Version: 1.0 In-Reply-To: <x34jdlyb6gf6asojjhzwpol5schyz4llk2ebrtzpb7ryje52u6@smbvzpoqcf6v> Hi Bruno, On Thu, Mar 20, 2025 at 12:12:10AM +0100, Alejandro Colomar wrote: > > At the same time, disallowing a leading '-' sign > > is a benefit as well. I consider it a misfeature that strtoul() parses > > "-3" successfully and returns ULONG_MAX-2, which was most certainly > > not intended by the user. >=20 > Agree; it is a misfeature. In my API a2i(), when the type passed in the > first parameter is an unsigned type, negative values are rejected. >=20 > I wonder if there's any legitimate user of that misfeature. I didn't > want to rule it out from a fundamental API just because I can't think of > a good use of it. >=20 > Maybe since we have people from many systems here, anyone who has even > seen a good use of strtoul(3) parsing negative values into an unsigned > type can comment. Maybe if we don't hear about it, we could consider it > useless and tighten it? Especially for an API that has explicit range > checks. >=20 > Would NetBSD be open to changing the implementation of strtou(3) to > reject negative input? I have filed a bug in NetBSD for reforming strtou(3): <https://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=3D59198> Let's see what they think about it. Cheers, Alex --=20 <https://www.alejandro-colomar.es/> --xmevghi4tmk2s4kb Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEES7Jt9u9GbmlWADAi64mZXMKQwqkFAmfbU5UACgkQ64mZXMKQ wqmzrg//Uc0j8RFjXzD+fMLBxCebBEF/AuQA7KaEn3iet1qpjNQ260ykafo3KyiS y/Xt8uXFEbNMSSd/9UNg0k12e+JWMRg9aQ9rzFVk8gNjEd1gDV2DwwKuNeEUg/e3 7ZBmruDUoKq1l7UEClZdSmQOAXMhFlwf3/NXuOVecbxHgTNqsRtiZ5ImJiwSPd7X v2SqdY/qWAinr5ArvLRqQztLmnC3+sPBQlAFhXR+daWON0bYiYbjtRnb8aBZabNM tSjgg8xGx0tjbMC8Edfelgbd/nat3bI9yoOu9L4L7G0JSgIGjh4Tgs3bIDzXQ1GW +BTLveB1u51FUTdr9sXj1ljIVPTaBFKqNM4gEjoe2EjAUijqz1UfJk+ytlVErhOm vEfaQHPZMkuOJyYpOn1S92SAaA0+9EYdfarepLqADg+gTFf0zVgRb908ZMj6OWjG 1A3m3DSS84NVIygzAOFWe3qWg1bRJ7p0vC/FH8HWMQpK0Xt9FjIIsZ2M2SClFCu+ YZHN/BKM9pzxxwF+QBaf7Aj4fPY/axoAHx1c/McVh+BqzWNWcepnr4gYBqrupj4N ZbzfOZD26p4HPhBXIf1pUtTVsgZYWZgrGvV7+t+KUBAGuxlbDv5pnC31kNe7eqam tNiOECu5tz1P2F6sAsWeNm96OoYeAriCrU1gLbaQt9fSW0knHzk= =G+aE -----END PGP SIGNATURE----- --xmevghi4tmk2s4kb--