[manual]: rawmemchr(3) and UB
Alejandro Colomar
alx.manpages@gmail.com
Fri Dec 30 10:31:09 GMT 2022
Hi Cristian,
On 12/29/22 20:50, Alejandro Colomar wrote:
> On 12/29/22 20:45, Cristian Rodríguez wrote:
>> On Thu, Dec 29, 2022 at 4:20 PM Alejandro Colomar via Libc-alpha
>> <libc-alpha@sourceware.org> wrote:
[...]
>>
>> The library itself uses this function mostly to find NULL as an
>> optimization. This is all before GCC handled all of this so it is
>> mostly obsolete.
>> gcc replaces null byte searches that use str*chr with s + strlen(s)
>> and expands memchr c=null and rawmemchr-like patterns inline.
>
> You mean that GCC does the following?:
>
>
> inline size_t
> strlen(const char *s)
> {
> return rawmemchr(s, '\0');
Obvious typo here: I forgot to subtract s.
> }
>
>
> If so, great, because I am writing a libc replacement, and was implementing
> strlen(3) exactly like that, which is why I needed the docs. It may be
> something not very useful, but I guess it's still very useful for libc internals.
>
It seems I misunderstood your email. I've seen that glibc implements
rawmemchr(3) in terms of strlen(3) and memchr(3). So it seems better to just
not implement this function in my library, and optimize strlen(3) directly. The
non-'\0' case seems useless, so probably not worth this function unless I see a
use for it.
Cheers,
Alex
--
<http://www.alejandro-colomar.es/>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20221230/d171f409/attachment.sig>
More information about the Libc-alpha
mailing list