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
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.