Skip to content

Commit 9dbdc19

Browse files
mertakmandagood
andauthored
Fix: Loop Variable Capturing Issue in Go 1.22 (#171)
* fix: remove copying loop variable * fix:utilize new int range syntax instead of traditional 3 clause loop * Remove unnecesary assignment Co-authored-by: Davis Goodin <[email protected]> --------- Co-authored-by: Davis Goodin <[email protected]>
1 parent fc0ef3a commit 9dbdc19

File tree

7 files changed

+5
-11
lines changed

7 files changed

+5
-11
lines changed

hash_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ var hashes = [...]crypto.Hash{
5656
func TestHash(t *testing.T) {
5757
msg := []byte("testing")
5858
for _, ch := range hashes {
59-
ch := ch
6059
t.Run(ch.String(), func(t *testing.T) {
6160
t.Parallel()
6261
if !openssl.SupportsHash(ch) {
@@ -90,7 +89,6 @@ func TestHash(t *testing.T) {
9089
func TestHash_BinaryMarshaler(t *testing.T) {
9190
msg := []byte("testing")
9291
for _, ch := range hashes {
93-
ch := ch
9492
t.Run(ch.String(), func(t *testing.T) {
9593
t.Parallel()
9694
if !openssl.SupportsHash(ch) {
@@ -122,7 +120,6 @@ func TestHash_BinaryMarshaler(t *testing.T) {
122120
func TestHash_Clone(t *testing.T) {
123121
msg := []byte("testing")
124122
for _, ch := range hashes {
125-
ch := ch
126123
t.Run(ch.String(), func(t *testing.T) {
127124
t.Parallel()
128125
if !openssl.SupportsHash(ch) {
@@ -163,7 +160,7 @@ func TestHash_ByteWriter(t *testing.T) {
163160
h := cryptoToHash(ch)()
164161
initSum := h.Sum(nil)
165162
bw := h.(io.ByteWriter)
166-
for i := 0; i < len(msg); i++ {
163+
for i := range len(msg) {
167164
bw.WriteByte(msg[i])
168165
}
169166
h.Reset()

hkdf_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ func TestHKDFMultiRead(t *testing.T) {
350350
hkdf := newHKDF(tt.hash, tt.master, tt.salt, tt.info)
351351
out := make([]byte, len(tt.out))
352352

353-
for b := 0; b < len(tt.out); b++ {
353+
for b := range len(tt.out) {
354354
n, err := io.ReadFull(hkdf, out[b:b+1])
355355
if n != 1 || err != nil {
356356
t.Errorf("test %d.%d: not enough output bytes: have %d, need %d .", i, b, n, len(tt.out))

hmac_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ func TestHMAC(t *testing.T) {
1818
{"sha512", NewSHA512},
1919
}
2020
for _, tt := range tests {
21-
tt := tt
2221
t.Run(tt.name, func(t *testing.T) {
2322
t.Parallel()
2423
h := NewHMAC(tt.fn, nil)

openssl.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ const wordBytes = bits.UintSize / 8
298298
func (z BigInt) byteSwap() {
299299
for i, d := range z {
300300
var n uint = 0
301-
for j := 0; j < wordBytes; j++ {
301+
for j := range wordBytes {
302302
n |= uint(byte(d)) << (8 * (wordBytes - j - 1))
303303
d >>= 8
304304
}
@@ -400,7 +400,7 @@ func bnToBinPad(bn C.GO_BIGNUM_PTR, to []byte) error {
400400
if pad < 0 {
401401
return errors.New("openssl: destination buffer too small")
402402
}
403-
for i := 0; i < pad; i++ {
403+
for i := range pad {
404404
to[i] = 0
405405
}
406406
if int(C.go_openssl_BN_bn2bin(bn, base(to[pad:]))) != n {

openssl_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func TestMain(m *testing.M) {
5858
fmt.Println("OpenSSL version:", openssl.VersionText())
5959
fmt.Println("FIPS enabled:", openssl.FIPS())
6060
status := m.Run()
61-
for i := 0; i < 5; i++ {
61+
for range 5 {
6262
// Run GC a few times to avoid false positives in leak detection.
6363
runtime.GC()
6464
// Sleep a bit to let the finalizers run.

rsa_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414

1515
func TestRSAKeyGeneration(t *testing.T) {
1616
for _, size := range []int{2048, 3072} {
17-
size := size
1817
t.Run(strconv.Itoa(size), func(t *testing.T) {
1918
t.Parallel()
2019
priv, pub := newRSAKey(t, size)

tls1prf_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ func TestTLS1PRF(t *testing.T) {
150150
t.Skip("TLS PRF is not supported")
151151
}
152152
for _, tt := range tls1prfTests {
153-
tt := tt
154153
t.Run(tt.hash.String(), func(t *testing.T) {
155154
if !openssl.SupportsHash(tt.hash) {
156155
t.Skip("skipping: hash not supported")

0 commit comments

Comments
 (0)