Fix buffer termination