[PATCH] resolv: add IPv6 support to inet_net_pton()
Job Snijders
job@fastly.com
Mon Mar 18 23:01:14 GMT 2024
On Mon, Mar 18, 2024 at 10:23:27AM +0100, Andreas Schwab wrote:
> On Mär 18 2024, Job Snijders wrote:
> > + __set_errno (0);
> > + lbits = strtol(sep, &ep, 10);
> > + if (sep[0] == '\0' || *ep != '\0') {
> > + __set_errno (ENOENT);
> > + return (-1);
> > + }
> > + if ((errno == ERANGE && (lbits == LONG_MAX || lbits == LONG_MIN))
> > + || (lbits > 128 || lbits < 0)) {
> > + __set_errno (EMSGSIZE);
> > + return (-1);
>
> I think the first half of the error check is redundant since we only
> accept values in the range [0,128] anyway.
This is an idiomatic error check. The compiler can optimize parts of
it, if the compiler feels they are not not neccessary. An argument
in support of idiomatic checks is that someone can visually inspect,
recognize, and know no checks were missed.
I'd like it if this libc implementation had strtonum() support like
described here: https://flak.tedunangst.com/post/the-design-of-strtonum
Would the project appreciate a patch?
Kind regards,
Job
More information about the Libc-alpha
mailing list