fix pos_to_offset() for last char