Fix bug in output buffer length