Not okay. You must use memmovewhen overlapping the source and destination.
It may work with memcpy, depending on your compiler implementation, but that’s not what you should rely on!
A typical naive implementation might be a byte copy (uint8) as follows:
typedef unsigned char uint8;
void * memcpy ( void * destination, const void * source, size_t num )
{
const uint8* pSrc = (const uint8*)source;
const uint8* const pSrcEnd = pSrc + num;
uint8* pDst = (uint8*)destination;
while (pSrc != pSrcEnd)
*(pDst++) = *(pSrc++);
return destination;
}
memcpy(buf, buf + 1, 2), memcpy(buf + 1, buf, 2)