public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Alejandro Colomar <alx.manpages@gmail.com>
To: "Cristian Rodríguez" <crrodriguez@opensuse.org>
Cc: GNU C Library <libc-alpha@sourceware.org>,
	linux-man <linux-man@vger.kernel.org>
Subject: Re: [manual]: rawmemchr(3) and UB
Date: Fri, 30 Dec 2022 11:31:09 +0100	[thread overview]
Message-ID: <8a005132-e724-6388-1834-73ef832b2ed1@gmail.com> (raw)
In-Reply-To: <9b215805-202d-9267-1fd9-57f994036f6f@gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 1369 bytes --]

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

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2022-12-30 10:31 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-29 19:19 Alejandro Colomar
2022-12-29 19:27 ` Alejandro Colomar
2022-12-29 19:45 ` Cristian Rodríguez
2022-12-29 19:50   ` Alejandro Colomar
2022-12-30 10:31     ` Alejandro Colomar [this message]
2022-12-30 13:13 Wilco Dijkstra
2022-12-30 14:16 ` Alejandro Colomar
2023-01-04 19:41 Wilco Dijkstra
2023-01-04 20:05 ` Alejandro Colomar
2023-01-04 20:19 ` G. Branden Robinson
2023-01-04 20:34   ` Alejandro Colomar
2023-01-05 12:21   ` G. Branden Robinson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8a005132-e724-6388-1834-73ef832b2ed1@gmail.com \
    --to=alx.manpages@gmail.com \
    --cc=crrodriguez@opensuse.org \
    --cc=libc-alpha@sourceware.org \
    --cc=linux-man@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).