Skip to content

Commit

Permalink
Use cloneSlice in unpackDataA and unpackDataAAAA
Browse files Browse the repository at this point in the history
I missed this pattern in #1432. These seem to be the only two
occurrences.

Updates #1432
  • Loading branch information
tmthrgd committed Nov 6, 2023
1 parent b18c05c commit 7d92076
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions msg_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 7d92076

Please sign in to comment.