buffer: use ssize_t for signed value.
buffer: check buffer->len before memmove().
buffer: readability cleanup.
buffer: get next power of two from required size.