term: handle bad utf8 chars in writeutf8()