fix string index overrun bug