Remove last \n or \r in buffer