4 ms·
Something like the following: void* pedanticmemmove(void *dst, const void *src, size_t n) { char buf[n > THRESHOLD ? 1 : n]; char *p = n > THRESHOLD
by slrz 10y ago
Something like the following:
void*
pedanticmemmove(void *dst, const void *src, size_t n)
{
char buf[n > THRESHOLD ? 1 : n];
char *p = n > THRESHOLD ? xmalloc(n) : buf;
memcpy(p, src, n);
memcpy(dst, p, n);
if (n > THRESHOLD)
free(p);
return dst;
}
But yeah, the alloca(3) variant is a bit nicer to look at and probably results in exactly the same code (but is non-standard, of course).