Fix invalid write on 0 length template string.

We cannot allocate a 0 length string and then try to write to it.