Skip to content

Commit 32e2038

Browse files
kolyshkintklauser
authored andcommitted
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 <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> Reviewed-by: Tobias Klauser <[email protected]> Reviewed-by: Sean Liao <[email protected]> Reviewed-by: Mark Freeman <[email protected]>
1 parent 137f2ed commit 32e2038

File tree

3 files changed

+3
-9
lines changed

3 files changed

+3
-9
lines changed

unix/fdset.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,5 @@ func (fds *FdSet) IsSet(fd int) bool {
2323

2424
// Zero clears the set fds.
2525
func (fds *FdSet) Zero() {
26-
for i := range fds.Bits {
27-
fds.Bits[i] = 0
28-
}
26+
clear(fds.Bits[:])
2927
}

unix/ifreq_linux.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ func (ifr *Ifreq) SetUint32(v uint32) {
111111
// clear zeroes the ifreq's union field to prevent trailing garbage data from
112112
// being sent to the kernel if an ifreq is reused.
113113
func (ifr *Ifreq) clear() {
114-
for i := range ifr.raw.Ifru {
115-
ifr.raw.Ifru[i] = 0
116-
}
114+
clear(ifr.raw.Ifru[:])
117115
}
118116

119117
// TODO(mdlayher): export as IfreqData? For now we can provide helpers such as

unix/syscall_linux.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -801,9 +801,7 @@ func (sa *SockaddrPPPoE) sockaddr() (unsafe.Pointer, _Socklen, error) {
801801
// one. The kernel expects SID to be in network byte order.
802802
binary.BigEndian.PutUint16(sa.raw[6:8], sa.SID)
803803
copy(sa.raw[8:14], sa.Remote)
804-
for i := 14; i < 14+IFNAMSIZ; i++ {
805-
sa.raw[i] = 0
806-
}
804+
clear(sa.raw[14 : 14+IFNAMSIZ])
807805
copy(sa.raw[14:], sa.Dev)
808806
return unsafe.Pointer(&sa.raw), SizeofSockaddrPPPoX, nil
809807
}

0 commit comments

Comments
 (0)