fixed index check to make sure theres enough room for the last element to be a \0