Why stringfy an array of UInt8s empties it?

For me the problem arose in an attempt to write differently and compare the performance of the various proposed solutions to this problem.
It didn’t take me long to find where the problem was, but in much more complex code this “hidden” behavior can be much harder to spot.


function multisbs3(str,sstr, s)
    cstr,csstr,cs=codeunits.([str,sstr, s])
    lcstr,lcsstr,lcs = length.([cstr,csstr,cs])
    l=lcs-(lcstr-lcsstr)
    fp=findfirst(cstr, cs)
    tmp=Vector{UInt8}(undef,l)
    res=Vector{String}(undef,4)
    j=1
    while !isnothing(fp)
        fs,ls=first(fp),last(fp)
        copyto!(tmp,1, cs,1,fs-1)
        copyto!(tmp,fs,csstr)
        copyto!(tmp,ls,cs,ls+1,lcs-ls)
        res[j]=String(copy(tmp))
        j+=1
        fp=findnext(cstr, cs,first(fp)+1)
    end
    res
end