unix: use Go 1.21+ clear built-in Inspired by CL 698495. Change-Id: Ic6ff68a60d41b6ffb6a28f523597c5d36c1e4d2f Reviewed-on: https://go-review.googlesource.com/c/sys/+/704915 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Sean Liao <sean@liao.dev> Reviewed-by: Mark Freeman <markfreeman@google.com>
diff --git a/unix/fdset.go b/unix/fdset.go index 9e83d18..62ed126 100644 --- a/unix/fdset.go +++ b/unix/fdset.go
@@ -23,7 +23,5 @@ // Zero clears the set fds. func (fds *FdSet) Zero() { - for i := range fds.Bits { - fds.Bits[i] = 0 - } + clear(fds.Bits[:]) }
diff --git a/unix/ifreq_linux.go b/unix/ifreq_linux.go index 848840a..309f5a2 100644 --- a/unix/ifreq_linux.go +++ b/unix/ifreq_linux.go
@@ -111,9 +111,7 @@ // clear zeroes the ifreq's union field to prevent trailing garbage data from // being sent to the kernel if an ifreq is reused. func (ifr *Ifreq) clear() { - for i := range ifr.raw.Ifru { - ifr.raw.Ifru[i] = 0 - } + clear(ifr.raw.Ifru[:]) } // TODO(mdlayher): export as IfreqData? For now we can provide helpers such as
diff --git a/unix/syscall_linux.go b/unix/syscall_linux.go index 4958a65..9439af9 100644 --- a/unix/syscall_linux.go +++ b/unix/syscall_linux.go
@@ -801,9 +801,7 @@ // one. The kernel expects SID to be in network byte order. binary.BigEndian.PutUint16(sa.raw[6:8], sa.SID) copy(sa.raw[8:14], sa.Remote) - for i := 14; i < 14+IFNAMSIZ; i++ { - sa.raw[i] = 0 - } + clear(sa.raw[14 : 14+IFNAMSIZ]) copy(sa.raw[14:], sa.Dev) return unsafe.Pointer(&sa.raw), SizeofSockaddrPPPoX, nil }