From 3b3a5b7c6a9ac71cdc02d90cfee32362706f2353 Mon Sep 17 00:00:00 2001 From: Tom Thorogood Date: Mon, 26 Nov 2018 12:00:33 +1030 Subject: [PATCH] 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. --- msg.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) 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