Fix undefined behavior in decoder.

Use memmove() for copying overlapping buffers.