use new clear builtin to clear bufs

This commit is contained in:
prof awk
2023-11-27 19:43:25 +02:00
parent 815dade355
commit 4d30f2c9ef
9 changed files with 11 additions and 36 deletions
+1 -3
View File
@@ -87,9 +87,7 @@ func newChunk(size int) *chunk {
} else {
pool := getChunkPool(size)
c = pool.Get().(*chunk)
for i := range c.data {
c.data[i] = 0
}
clear(c.data)
}
c.InitRefs()
return c
+1 -6
View File
@@ -221,12 +221,7 @@ func Zero(dst Block) (int, error) {
if !dst.needSafecopy {
bs := dst.ToSlice()
if !sync.RaceEnabled {
// If the race detector isn't enabled, the golang
// compiler replaces the next loop with memclr
// (https://github.com/golang/go/issues/5373).
for i := range bs {
bs[i] = 0
}
clear(bs)
} else {
bsLen := len(bs)
if bsLen == 0 {
+2 -6
View File
@@ -111,9 +111,7 @@ func (s *State) Fork() State {
// Reset resets s to its initial state.
func (s *State) Reset() {
f := *s
for i := range f {
f[i] = 0
}
clear(f)
initX86FPState(&f[0], cpuid.HostFeatureSet().UseXsave())
}
@@ -269,9 +267,7 @@ func (s *State) SanitizeUser(featureSet cpuid.FeatureSet) {
hostarch.ByteOrder.PutUint64(f[xstateBVOffset:], xstateBV)
// Force XCOMP_BV and reserved bytes in the XSAVE header to 0.
reserved := f[xsaveHeaderZeroedOffset : xsaveHeaderZeroedOffset+xsaveHeaderZeroedBytes]
for i := range reserved {
reserved[i] = 0
}
clear(reserved)
}
}
+1 -3
View File
@@ -815,9 +815,7 @@ func (f *MemoryFile) Decommit(fr memmap.FileRange) error {
func (f *MemoryFile) manuallyZero(fr memmap.FileRange) error {
return f.forEachMappingSlice(fr, func(bs []byte) {
for i := range bs {
bs[i] = 0
}
clear(bs)
})
}
+2 -6
View File
@@ -150,9 +150,7 @@ func (cb *getdentsCallback) Handle(dirent vfs.Dirent) error {
// Zero out all remaining bytes in buf, including the NUL terminator
// after dirent.Name.
bufTail := buf[19+len(dirent.Name):]
for i := range bufTail {
bufTail[i] = 0
}
clear(bufTail)
cb.copied += size
} else {
// struct linux_dirent {
@@ -188,9 +186,7 @@ func (cb *getdentsCallback) Handle(dirent vfs.Dirent) error {
// after dirent.Name and the zero padding byte between the name and
// dirent type.
bufTail := buf[18+len(dirent.Name) : size-1]
for i := range bufTail {
bufTail[i] = 0
}
clear(bufTail)
buf[size-1] = dirent.Type
cb.copied += size
}
+1 -3
View File
@@ -1137,9 +1137,7 @@ func (s IPv4OptionsSerializer) Serialize(b []byte) uint8 {
// header ends on a 32 bit boundary. The padding is zero.
padded := padIPv4OptionsLength(total)
b = b[:padded-total]
for i := range b {
b[i] = 0
}
clear(b)
return padded
}
+1 -3
View File
@@ -130,9 +130,7 @@ func padIPv6Option(b []byte) {
b[ipv6ExtHdrOptionTypeOffset] = uint8(ipv6Pad1ExtHdrOptionIdentifier)
default: // Pad with PadN.
s := b[ipv6ExtHdrOptionPayloadOffset:]
for i := range s {
s[i] = 0
}
clear(s)
b[ipv6ExtHdrOptionTypeOffset] = uint8(ipv6PadNExtHdrOptionIdentifier)
b[ipv6ExtHdrOptionLengthOffset] = uint8(len(s))
}
+1 -3
View File
@@ -58,9 +58,7 @@ func (b *BytesIO) ZeroOut(ctx context.Context, addr hostarch.Addr, toZero int64,
return 0, rngErr
}
zeroSlice := b.Bytes[int(addr) : int(addr)+rngN]
for i := range zeroSlice {
zeroSlice[i] = 0
}
clear(zeroSlice)
return int64(rngN), rngErr
}
+1 -3
View File
@@ -81,9 +81,7 @@ func RandomizeValue(x any) {
// This is used for zeroing padding fields after calling RandomizeValue.
func reflectZeroPaddingFields(r reflect.Type, data []byte, zero bool) {
if zero {
for i := range data {
data[i] = 0
}
clear(data)
}
switch r.Kind() {
case reflect.Int8, reflect.Uint8, reflect.Int16, reflect.Uint16, reflect.Int32, reflect.Uint32, reflect.Int64, reflect.Uint64: