memmove copies a byte range even when the source and destination overlap. It is the safer choice when shifting data within one allocated buffer. section 13.1.1
Shifting part of a circular buffer
When resizing a circular buffer, an upper chunk may need to move toward the new end while remaining inside the same allocation: memmove(ntab + nstart, ntab + ostart, ulen * sizeof(double)); The corresponding non-overlapping case uses memcpy. TAKEAWAY: choose memcpy only when source and destination cannot overlap; use memmove when they may. section 13.1.1
// non-empty, and there were already two separate chunks
if (ostart+len > olen) {
size_t ulen = olen - ostart;
size_t llen = len - ulen;
if (llen <= (nlen - olen)) {
/* Copy the lower one up after the old end. */
memcpy(ntab + olen, ntab,
llen*sizeof(double));
} else {
/* Move the upper one up to the new end. */
nstart = nlen - ulen;
memmove(ntab + nstart, ntab + ostart,
ulen*sizeof(double));
}
}
Inspect the resize listing to see the overlapping shift beside the alternative memcpy operation. section 13.1.1

