[PATCH] nss: remove undefined behavior and optimize getaddrinfo

Sam James sam@gentoo.org
Mon Apr 28 05:31:27 GMT 2025


Collin Funk <collin.funk1@gmail.com> writes:

> On x86-64 and compiling with -O2 using stdc_leading_zeros compiles to
> the bsr instruction.  The fls function removed by this patch is inlined
> but still loops while checking each bit individually.
>
> * nss/getaddrinfo.c: Include <stdbit.h>.
> (fls): Remove function.  This function contains a left shift of 31 on an
> 'int' which is undefined.
> (rfc3484_sort): Use stdc_leading_zeros instead of fls.

FWIW, azanella has a fix for this on his branch too:
https://inbox.sourceware.org/glibc-cvs/20250425205122.7A5333858D3C@sourceware.org/T/#u.

Are you running using his UBSAN patches, or doing something else (just
noticed by inspection or ...)?


More information about the Libc-alpha mailing list