Add boundary check

When the memory extends, the \0 may not be appended.