Make sure buffer is always NUL terminated.