mirror of
https://github.com/golang/go
synced 2024-11-25 11:17:56 -07:00
all: make use of builtin clear
Change-Id: I1df0685c75fc1044ba46003a69ecc7dfc53bbc2b Reviewed-on: https://go-review.googlesource.com/c/go/+/574675 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Than McIntosh <thanm@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
979b34b37c
commit
d4cc35c4fd
@ -904,9 +904,7 @@ func returnRecursiveZip() (r io.ReaderAt, size int64) {
|
||||
// type zeros struct{}
|
||||
//
|
||||
// func (zeros) Read(b []byte) (int, error) {
|
||||
// for i := range b {
|
||||
// b[i] = 0
|
||||
// }
|
||||
// clear(b)
|
||||
// return len(b), nil
|
||||
// }
|
||||
//
|
||||
|
@ -814,8 +814,6 @@ func TestSuffixSaver(t *testing.T) {
|
||||
type zeros struct{}
|
||||
|
||||
func (zeros) Read(p []byte) (int, error) {
|
||||
for i := range p {
|
||||
p[i] = 0
|
||||
}
|
||||
clear(p)
|
||||
return len(p), nil
|
||||
}
|
||||
|
@ -176,9 +176,7 @@ func (g *gcmAsm) Open(dst, nonce, ciphertext, data []byte) ([]byte, error) {
|
||||
gcmAesFinish(&g.productTable, &tagMask, &expectedTag, uint64(len(ciphertext)), uint64(len(data)))
|
||||
|
||||
if subtle.ConstantTimeCompare(expectedTag[:g.tagSize], tag) != 1 {
|
||||
for i := range out {
|
||||
out[i] = 0
|
||||
}
|
||||
clear(out)
|
||||
return nil, errOpen
|
||||
}
|
||||
|
||||
|
@ -212,9 +212,7 @@ func (g *gcmAsm) Open(dst, nonce, ciphertext, data []byte) ([]byte, error) {
|
||||
ret, out := sliceForAppend(dst, len(ciphertext))
|
||||
|
||||
if subtle.ConstantTimeCompare(expectedTag[:g.tagSize], tag) != 1 {
|
||||
for i := range out {
|
||||
out[i] = 0
|
||||
}
|
||||
clear(out)
|
||||
return nil, errOpen
|
||||
}
|
||||
|
||||
|
@ -271,9 +271,7 @@ func (g *gcmAsm) Open(dst, nonce, ciphertext, data []byte) ([]byte, error) {
|
||||
// so overwrites dst in the event of a tag mismatch. That
|
||||
// behavior is mimicked here in order to be consistent across
|
||||
// platforms.
|
||||
for i := range out {
|
||||
out[i] = 0
|
||||
}
|
||||
clear(out)
|
||||
return nil, errOpen
|
||||
}
|
||||
|
||||
@ -363,9 +361,7 @@ func (g *gcmKMA) Open(dst, nonce, ciphertext, data []byte) ([]byte, error) {
|
||||
// so overwrites dst in the event of a tag mismatch. That
|
||||
// behavior is mimicked here in order to be consistent across
|
||||
// platforms.
|
||||
for i := range out {
|
||||
out[i] = 0
|
||||
}
|
||||
clear(out)
|
||||
return nil, errOpen
|
||||
}
|
||||
|
||||
|
@ -234,9 +234,7 @@ func (g *gcm) Open(dst, nonce, ciphertext, data []byte) ([]byte, error) {
|
||||
// so overwrites dst in the event of a tag mismatch. That
|
||||
// behavior is mimicked here in order to be consistent across
|
||||
// platforms.
|
||||
for i := range out {
|
||||
out[i] = 0
|
||||
}
|
||||
clear(out)
|
||||
return nil, errOpen
|
||||
}
|
||||
|
||||
|
@ -412,9 +412,7 @@ type zr struct{}
|
||||
|
||||
// Read replaces the contents of dst with zeros. It is safe for concurrent use.
|
||||
func (zr) Read(dst []byte) (n int, err error) {
|
||||
for i := range dst {
|
||||
dst[i] = 0
|
||||
}
|
||||
clear(dst)
|
||||
return len(dst), nil
|
||||
}
|
||||
|
||||
|
@ -457,9 +457,7 @@ var zeroReader = zr{}
|
||||
|
||||
// Read replaces the contents of dst with zeros. It is safe for concurrent use.
|
||||
func (zr) Read(dst []byte) (n int, err error) {
|
||||
for i := range dst {
|
||||
dst[i] = 0
|
||||
}
|
||||
clear(dst)
|
||||
return len(dst), nil
|
||||
}
|
||||
|
||||
|
@ -45,9 +45,7 @@ func Example_ed25519ctx() {
|
||||
type zeroReader struct{}
|
||||
|
||||
func (zeroReader) Read(buf []byte) (int, error) {
|
||||
for i := range buf {
|
||||
buf[i] = 0
|
||||
}
|
||||
clear(buf)
|
||||
return len(buf), nil
|
||||
}
|
||||
|
||||
|
@ -76,9 +76,7 @@ func (x *Nat) expand(n int) *Nat {
|
||||
return x
|
||||
}
|
||||
extraLimbs := x.limbs[len(x.limbs):n]
|
||||
for i := range extraLimbs {
|
||||
extraLimbs[i] = 0
|
||||
}
|
||||
clear(extraLimbs)
|
||||
x.limbs = x.limbs[:n]
|
||||
return x
|
||||
}
|
||||
@ -89,9 +87,7 @@ func (x *Nat) reset(n int) *Nat {
|
||||
x.limbs = make([]uint, n)
|
||||
return x
|
||||
}
|
||||
for i := range x.limbs {
|
||||
x.limbs[i] = 0
|
||||
}
|
||||
clear(x.limbs)
|
||||
x.limbs = x.limbs[:n]
|
||||
return x
|
||||
}
|
||||
|
@ -18,10 +18,7 @@ import (
|
||||
type zeroSource struct{}
|
||||
|
||||
func (zeroSource) Read(b []byte) (n int, err error) {
|
||||
for i := range b {
|
||||
b[i] = 0
|
||||
}
|
||||
|
||||
clear(b)
|
||||
return len(b), nil
|
||||
}
|
||||
|
||||
|
@ -310,10 +310,7 @@ Dialing:
|
||||
type zeroSource struct{}
|
||||
|
||||
func (zeroSource) Read(b []byte) (n int, err error) {
|
||||
for i := range b {
|
||||
b[i] = 0
|
||||
}
|
||||
|
||||
clear(b)
|
||||
return len(b), nil
|
||||
}
|
||||
|
||||
|
@ -318,9 +318,7 @@ type bytesKey struct {
|
||||
}
|
||||
|
||||
func (k *bytesKey) clear() {
|
||||
for i := range k.b {
|
||||
k.b[i] = 0
|
||||
}
|
||||
clear(k.b)
|
||||
}
|
||||
func (k *bytesKey) random(r *rand.Rand) {
|
||||
randBytes(r, k.b)
|
||||
|
@ -13,9 +13,7 @@ import (
|
||||
// source code to 0.
|
||||
func ResetCoverage() {
|
||||
cov := coverage()
|
||||
for i := range cov {
|
||||
cov[i] = 0
|
||||
}
|
||||
clear(cov)
|
||||
}
|
||||
|
||||
// SnapshotCoverage copies the current counter values into coverageSnapshot,
|
||||
|
@ -69,9 +69,7 @@ func (fd *FD) Writev(v *[][]byte) (int64, error) {
|
||||
TestHookDidWritev(int(wrote))
|
||||
n += int64(wrote)
|
||||
consume(v, int64(wrote))
|
||||
for i := range iovecs {
|
||||
iovecs[i] = syscall.Iovec{}
|
||||
}
|
||||
clear(iovecs)
|
||||
if err != nil {
|
||||
if err == syscall.EINTR {
|
||||
continue
|
||||
|
@ -63,9 +63,7 @@ func ReadGCStats(stats *GCStats) {
|
||||
|
||||
if len(stats.PauseQuantiles) > 0 {
|
||||
if n == 0 {
|
||||
for i := range stats.PauseQuantiles {
|
||||
stats.PauseQuantiles[i] = 0
|
||||
}
|
||||
clear(stats.PauseQuantiles)
|
||||
} else {
|
||||
// There's room for a second copy of the data in stats.Pause.
|
||||
// See the allocation at the top of the function.
|
||||
|
@ -544,9 +544,7 @@ func bulkBarrierPreWriteSrcOnly(dst, src, size uintptr, typ *abi.Type) {
|
||||
func (s *mspan) initHeapBits(forceClear bool) {
|
||||
if (!s.spanclass.noscan() && heapBitsInSpan(s.elemsize)) || s.isUserArenaChunk {
|
||||
b := s.heapBits()
|
||||
for i := range b {
|
||||
b[i] = 0
|
||||
}
|
||||
clear(b)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -240,9 +240,7 @@ func TestMemmoveAtomicity(t *testing.T) {
|
||||
for i := range src {
|
||||
src[i] = &x
|
||||
}
|
||||
for i := range dst {
|
||||
dst[i] = nil
|
||||
}
|
||||
clear(dst)
|
||||
|
||||
var ready atomic.Uint32
|
||||
go func() {
|
||||
|
@ -205,9 +205,7 @@ func netpoll(delay int64) (gList, int32) {
|
||||
}
|
||||
|
||||
evts = evts[:len(pollsubs)]
|
||||
for i := range evts {
|
||||
evts[i] = event{}
|
||||
}
|
||||
clear(evts)
|
||||
|
||||
retry:
|
||||
var nevents size
|
||||
|
@ -80,9 +80,7 @@ func writeErr(b []byte) {
|
||||
if v == '\n' || writePos == len(dst)-1 {
|
||||
dst[writePos] = 0
|
||||
write(writeFD, unsafe.Pointer(&writeBuf[0]), int32(hlen+writePos))
|
||||
for i := range dst {
|
||||
dst[i] = 0
|
||||
}
|
||||
clear(dst)
|
||||
writePos = 0
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user