Fix string index out of bounds exception, credit to @void256 for finding
and reporting.