From: Paul Eggert <eggert@cs.ucla.edu>
To: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>,
libc-alpha <libc-alpha@sourceware.org>
Cc: post+sourceware.org@ralfj.de
Subject: Re: Support for memcpy with equal source and destination
Date: Fri, 24 Nov 2023 23:48:53 -0800 [thread overview]
Message-ID: <c1d5fd5a-50ce-44b1-97a6-9684e117eb46@cs.ucla.edu> (raw)
In-Reply-To: <1e8beece-f865-4309-a28f-6782135e2a8a@linaro.org>
I see several areas of possible confusion, so if we make this change to
the glibc documentation, the new documentation should make the following
clear:
* This is a GNU extension, and other C libraries might not guarantee
this (not surprising). Also, other C compilers might not guarantee this
even when used with glibc (somewhat more surprising).
* GCC and other compilers might warn about memcpy (X, X, SIZE) even if
it is supported.
* This an exception to the usual rule about "restrict", since the
prototype says "restrict" but it's OK if the two pointers are the same
(so "restrict" now means that they cannot overlap other than being
equal, just for this particular function).
* The pointers must point to SIZE bytes even when SOURCE == DESTINATION.
For example, memcpy (&errno, &errno, SIZE_MAX) is not valid.
* If SIZE is nonzero, the destination must be writable even when SOURCE
== DESTINATION.
* mempcpy, strcpy, and stpcpy are like memcpy in the above respects.
(Are there other functions for which we want to make similar guarantees?)
The issue with null-or-invalid pointers and size zero is independent of
this, as far as I can see, so it can be treated separately.
next prev parent reply other threads:[~2023-11-25 7:48 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-23 12:14 Adhemerval Zanella Netto
2023-11-25 7:48 ` Paul Eggert [this message]
2023-11-25 8:20 ` Ralf Jung
2023-11-25 17:11 ` Paul Eggert
2023-11-27 11:15 ` Ralf Jung
2023-11-27 11:46 ` Alexander Monakov
2023-11-27 12:34 ` Ralf Jung
2023-11-27 14:25 ` Alexander Monakov
2023-11-27 14:38 Wilco Dijkstra
2023-11-27 14:45 ` Ralf Jung
2023-11-27 14:53 ` Zack Weinberg
2023-11-27 15:02 ` enh
2023-11-27 19:28 Aaron Peter Bachmann
2023-11-27 19:39 ` Paul Eggert
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=c1d5fd5a-50ce-44b1-97a6-9684e117eb46@cs.ucla.edu \
--to=eggert@cs.ucla.edu \
--cc=adhemerval.zanella@linaro.org \
--cc=libc-alpha@sourceware.org \
--cc=post+sourceware.org@ralfj.de \
/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).