Fix infinite loop at EOF.