On 2026-01-05, highcrew <
high.crew3868@fastmail.com> wrote:
In my understanding, if we call buffer_append(&x, &y) for x.bytes and
y.bytes pointing to overlapping areas of the same array, we get UB by
the first two parameters of memcpy being restrict-qualified pointers.
Nope! The standard doesn't provide a /definition/ of memcpy.
And restrict qualifiers on pointer parameters in a /declaration/ don't
mean anything (and need not be repeated in the definition).
memcpy is not required to take overlapping objects for the
reason that its description says so.
That situation existed long before there was a restrict, and has
implications in the absence of restrict. Various ways of implemeting a memcpy-like function will produce various unexpected results when
objects overlap, even without any undefined behavior taking place. For instance if we copy byte-by-byte, from lowest address to highest, then
we end up writing into memory that our loop is about to read from,
corrupting the data.
In order not to place any restrictions on how a memcpy may be
implemented, whether with the help of restrict pointers, or assembly
language or whatever else, the standard makes overlapping inputs
undefined.
--
TXR Programming Language:
http://nongnu.org/txr
Cygnal: Cygwin Native Application Library:
http://kylheku.com/cygnal
Mastodon: @
Kazinator@mstdn.ca
--- PyGate Linux v1.5.2
* Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)