Only append terminating '\0' when necessary.