Fix buffer length trim