Replace another for loop with copy in packDomainName

This change is included as a separate commit because this loop is not as
trivial as the others.
This commit is contained in:
Tom Thorogood 2018-11-26 12:00:33 +10:30
parent 8d08c56229
commit 3b3a5b7c6a
No known key found for this signature in database
GPG Key ID: 86C63CDA416C6D2F
1 changed files with 6 additions and 8 deletions

14
msg.go
View File

@ -251,15 +251,13 @@ func packDomainName(s string, msg []byte, off int, compression map[string]int, c
}
offset := off
off++
for j := begin; j < i; j++ {
if off+1 > lenmsg {
return lenmsg, labels, ErrBuf
}
if msg != nil {
msg[off] = bs[j]
}
off++
if off+(i-begin) > lenmsg {
return lenmsg, labels, ErrBuf
}
if msg != nil {
copy(msg[off:], bs[begin:i])
}
off += i - begin
if compress && !bsFresh {
roBs = string(bs)
bsFresh = true