[PATCH] resolv: add IPv6 support to inet_net_pton()

Andreas Schwab schwab@suse.de
Tue Mar 19 08:20:26 GMT 2024


On Mär 18 2024, Job Snijders wrote:

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

But it unnecessarily modifies errno (which the compiler cannot optimize
out), and sets it to zero when no error occurs, which no library routine
must ever do.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


More information about the Libc-alpha mailing list