From 7d9207659d9110918e84c2fed0174c2c0299af9d Mon Sep 17 00:00:00 2001 From: Tom Thorogood Date: Mon, 6 Nov 2023 16:00:27 +1030 Subject: [PATCH] Use cloneSlice in unpackDataA and unpackDataAAAA I missed this pattern in #1432. These seem to be the only two occurrences. Updates #1432 --- msg_helpers.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/msg_helpers.go b/msg_helpers.go index 8582fc0ad..3a6cddfa0 100644 --- a/msg_helpers.go +++ b/msg_helpers.go @@ -20,9 +20,7 @@ func unpackDataA(msg []byte, off int) (net.IP, int, error) { if off+net.IPv4len > len(msg) { return nil, len(msg), &Error{err: "overflow unpacking a"} } - a := append(make(net.IP, 0, net.IPv4len), msg[off:off+net.IPv4len]...) - off += net.IPv4len - return a, off, nil + return cloneSlice(msg[off : off+net.IPv4len]), off + net.IPv4len, nil } func packDataA(a net.IP, msg []byte, off int) (int, error) { @@ -47,9 +45,7 @@ func unpackDataAAAA(msg []byte, off int) (net.IP, int, error) { if off+net.IPv6len > len(msg) { return nil, len(msg), &Error{err: "overflow unpacking aaaa"} } - aaaa := append(make(net.IP, 0, net.IPv6len), msg[off:off+net.IPv6len]...) - off += net.IPv6len - return aaaa, off, nil + return cloneSlice(msg[off : off+net.IPv6len]), off + net.IPv6len, nil } func packDataAAAA(aaaa net.IP, msg []byte, off int) (int, error) {