public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Alejandro Colomar <alx.manpages@gmail.com>
To: GNU C Library <libc-alpha@sourceware.org>
Cc: linux-man <linux-man@vger.kernel.org>
Subject: Re: [manual]: rawmemchr(3) and UB
Date: Thu, 29 Dec 2022 20:27:19 +0100	[thread overview]
Message-ID: <7870c368-2aa3-3f04-7cb0-5c4596f5a063@gmail.com> (raw)
In-Reply-To: <82db6083-5daa-66f9-2a4e-2823168f1574@gmail.com>


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



On 12/29/22 20:19, Alejandro Colomar via Libc-alpha wrote:
> Hi,
> 
> I was reading rawmemchr(3), and found some funny text:
> 
> RETURN VALUE
>         The  memchr()  and memrchr() functions return a pointer to the matching
>         byte or NULL if the character does not occur in the given memory area.
> 
>         The rawmemchr() function returns a pointer to the matching byte, if one
>         is found.  If no matching byte is found, the result is unspecified.
> 
> 
> Of course, if the byte is not found, the result is not unspecified, but rather 
> undefined, and a crash is very likely so maybe there's not even a result.  I 
> thought this might be a thinko of the manual page, but the glibc manual seems to 
> have similar text:
> 
> 
> <https://www.gnu.org/software/libc/manual/html_mono/libc.html#index-rawmemchr>
> "
> The rawmemchr function exists for just this situation which is surprisingly 
> frequent. The interface is similar to memchr except that the size parameter is 
> missing. The function will look beyond the end of the block pointed to by block 
> in case the programmer made an error in assuming that the byte c is present in 
> the block. In this case the result is unspecified. Otherwise the return value is 
> a pointer to the located byte.
> "
> 
> 
> That test can't be true, and the result of that function when there's no match 

s/test/text/

> can't be anything other than UB, and likely a crash.  Please fix the doc.
> 
> Cheers,
> 
> Alex

-- 
<http://www.alejandro-colomar.es/>

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

  reply	other threads:[~2022-12-29 19:27 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 [this message]
2022-12-29 19:45 ` Cristian Rodríguez
2022-12-29 19:50   ` Alejandro Colomar
2022-12-30 10:31     ` Alejandro Colomar
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=7870c368-2aa3-3f04-7cb0-5c4596f5a063@gmail.com \
    --to=alx.manpages@gmail.com \
    --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).