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 #1946

Merged
merged 1 commit into from
Mar 22, 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 @@ -495,7 +495,5 @@ func (ks *KeyStore) ImportPreSaleKey(keyJSON []byte, passphrase string) (account
// 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 @@ -288,7 +288,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 ctxc/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,6 @@ const (
maxQueuedBlockAnns = 4
)

// 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
}

// PeerInfo represents a short summary of the Cortex sub-protocol metadata known
// about a connected peer.
type PeerInfo struct {
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