Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: use min/max/clear from go1.21 #29307

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions accounts/keystore/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,5 @@ func (ks *KeyStore) isUpdating() bool {
// zeroKey zeroes a private key in memory.
func zeroKey(k *ecdsa.PrivateKey) {
b := k.D.Bits()
for i := range b {
b[i] = 0
}
clear(b)
}
4 changes: 1 addition & 3 deletions core/vm/analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ func BenchmarkJumpdestOpAnalysis(bench *testing.B) {
bits := make(bitvec, len(code)/8+1+4)
b.ResetTimer()
for i := 0; i < b.N; i++ {
for j := range bits {
bits[j] = 0
}
clear(bits)
codeBitmapInternal(code, bits)
}
}
Expand Down
4 changes: 1 addition & 3 deletions crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,5 @@ func PubkeyToAddress(p ecdsa.PublicKey) common.Address {
}

func zeroBytes(bytes []byte) {
for i := range bytes {
bytes[i] = 0
}
clear(bytes)
}
8 changes: 2 additions & 6 deletions crypto/secp256k1/scalar_mult_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,8 @@ func (BitCurve *BitCurve) ScalarMult(Bx, By *big.Int, scalar []byte) (*big.Int,
// Unpack the result and clear temporaries.
x := new(big.Int).SetBytes(point[:32])
y := new(big.Int).SetBytes(point[32:])
for i := range point {
point[i] = 0
}
for i := range padded {
scalar[i] = 0
}
clear(point)
clear(scalar)
if res != 1 {
return nil, nil
}
Expand Down
8 changes: 0 additions & 8 deletions eth/protocols/eth/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ const (
maxQueuedTxAnns = 4096
)

// max is a helper function which returns the larger of the two given integers.
func max(a, b int) int {
if a > b {
return a
}
return b
}

// Peer is a collection of relevant information we have about a `eth` peer.
type Peer struct {
id string // Unique ID for the peer, cached
Expand Down
9 changes: 1 addition & 8 deletions internal/era/era.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func (e *Era) readOffset(n uint64) (int64, error) {
)
e.mu.Lock()
defer e.mu.Unlock()
clearBuffer(e.buf[:])
clear(e.buf[:])
if _, err := e.f.ReadAt(e.buf[:], offOffset); err != nil {
return 0, err
}
Expand All @@ -248,13 +248,6 @@ func newSnappyReader(e *e2store.Reader, expectedType uint16, off int64) (io.Read
return snappy.NewReader(r), int64(n), err
}

// clearBuffer zeroes out the buffer.
func clearBuffer(buf []byte) {
for i := 0; i < len(buf); i++ {
buf[i] = 0
}
}

// metadata wraps the metadata in the block index.
type metadata struct {
start uint64
Expand Down
7 changes: 0 additions & 7 deletions metrics/sample_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,6 @@ func BenchmarkUniformSample1028(b *testing.B) {
benchmarkSample(b, NewUniformSample(1028))
}

func min(a, b int) int {
if a < b {
return a
}
return b
}

func TestExpDecaySample(t *testing.T) {
for _, tc := range []struct {
reservoirSize int
Expand Down
7 changes: 0 additions & 7 deletions p2p/discover/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,3 @@ type ReadPacket struct {
Data []byte
Addr *net.UDPAddr
}

func min(x, y int) int {
if x > y {
return y
}
return x
}
4 changes: 1 addition & 3 deletions p2p/discover/v5wire/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ func deriveKeys(hash hashFn, priv *ecdsa.PrivateKey, pub *ecdsa.PublicKey, n1, n
sec := session{writeKey: make([]byte, aesKeySize), readKey: make([]byte, aesKeySize)}
kdf.Read(sec.writeKey)
kdf.Read(sec.readKey)
for i := range eph {
eph[i] = 0
}
clear(eph)
return &sec
}

Expand Down
4 changes: 1 addition & 3 deletions rlp/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -1105,9 +1105,7 @@ func (s *Stream) readUint(size byte) (uint64, error) {
return uint64(b), err
default:
buffer := s.uintbuf[:8]
for i := range buffer {
buffer[i] = 0
}
clear(buffer)
start := int(8 - size)
if err := s.readFull(buffer[start:]); err != nil {
return 0, err
Expand Down
Loading