Replace simple loops with copy in packDomainName

This commit is contained in:
Tom Thorogood 2018-11-26 11:59:38 +10:30
parent ab9dd29c1d
commit 8d08c56229
No known key found for this signature in database
GPG Key ID: 86C63CDA416C6D2F
1 changed files with 2 additions and 6 deletions

8
msg.go
View File

@ -217,9 +217,7 @@ func packDomainName(s string, msg []byte, off int, compression map[string]int, c
roBs, bsFresh, escapedDot := s, true, false
for i := 0; i < ls; i++ {
if bs[i] == '\\' {
for j := i; j < ls-1; j++ {
bs[j] = bs[j+1]
}
copy(bs[i:ls-1], bs[i+1:])
ls--
if off+1 > lenmsg {
return lenmsg, labels, ErrBuf
@ -227,9 +225,7 @@ func packDomainName(s string, msg []byte, off int, compression map[string]int, c
// check for \DDD
if i+2 < ls && isDigit(bs[i]) && isDigit(bs[i+1]) && isDigit(bs[i+2]) {
bs[i] = dddToByte(bs[i:])
for j := i + 1; j < ls-2; j++ {
bs[j] = bs[j+2]
}
copy(bs[i+1:ls-2], bs[i+3:])
ls -= 2
}
escapedDot = bs[i] == '.'