diff --git a/msg.go b/msg.go index 09b1a6da..16644ea4 100644 --- a/msg.go +++ b/msg.go @@ -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