Note: I changed this to a `memcpy` because a freshly allocated buffer will never overlap with the second argument.