~skeeto/public-inbox

1

Re: My review of the C standard library in practice

Details
Message ID
<20230218081805.z57kyrbc6xzqlnx6@gen2.localdomain>
DKIM signature
missing
Download raw message
Re: Numeric conversion

One thing that I recently came to know about is the behavior of the
strtoul[l] functions when parsing negative numbers. Given that it's for
parsing unsigned numbers, you'd expect something like "-1" to error out
due to ERANGE.

However, that's not what it does. Instead it's defined to return `-1`
(i.e ULONG_MAX for `strtoul`):
https://port70.net/~nsz/c/c11/n1570.html#7.22.1.4p5
https://www.austingroupbugs.net/view.php?id=700

For 95%+ use-cases, I'd assume that this is going to be a
pitfall/unwanted behavior. So that gives yet another justification for
rolling your own integer parsers.

- NRK

Re: My review of the C standard library in practice

Details
Message ID
<20230219011154.ribqgp7t77mlzmbz@nullprogram.com>
In-Reply-To
<20230218081805.z57kyrbc6xzqlnx6@gen2.localdomain> (view parent)
DKIM signature
missing
Download raw message
Wow, I had no idea! I've assumed in the past it would be considered out of 
range. The specification's wording doesn't make this obvious, either. I've 
just added a note about it to the article.
Reply to thread Export thread (mbox)