Skip to content

Commit 8d72fc4

Browse files
committed
fix: copy loop var to avoid overwriting value
1 parent dac3d62 commit 8d72fc4

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

ledger/allegra.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ func (b *AllegraBlock) Era() Era {
4848
func (b *AllegraBlock) Transactions() []TransactionBody {
4949
ret := []TransactionBody{}
5050
for _, v := range b.TransactionBodies {
51-
ret = append(ret, &v)
51+
// Create temp var since we take the address and the loop var gets reused
52+
tmpVal := v
53+
ret = append(ret, &tmpVal)
5254
}
5355
return ret
5456
}

ledger/alonzo.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ func (b *AlonzoBlock) Era() Era {
4949
func (b *AlonzoBlock) Transactions() []TransactionBody {
5050
ret := []TransactionBody{}
5151
for _, v := range b.TransactionBodies {
52-
ret = append(ret, &v)
52+
// Create temp var since we take the address and the loop var gets reused
53+
tmpVal := v
54+
ret = append(ret, &tmpVal)
5355
}
5456
return ret
5557
}

ledger/babbage.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ func (b *BabbageBlock) Era() Era {
4949
func (b *BabbageBlock) Transactions() []TransactionBody {
5050
ret := []TransactionBody{}
5151
for _, v := range b.TransactionBodies {
52-
ret = append(ret, &v)
52+
// Create temp var since we take the address and the loop var gets reused
53+
tmpVal := v
54+
ret = append(ret, &tmpVal)
5355
}
5456
return ret
5557
}

ledger/mary.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ func (b *MaryBlock) Era() Era {
4848
func (b *MaryBlock) Transactions() []TransactionBody {
4949
ret := []TransactionBody{}
5050
for _, v := range b.TransactionBodies {
51-
ret = append(ret, &v)
51+
// Create temp var since we take the address and the loop var gets reused
52+
tmpVal := v
53+
ret = append(ret, &tmpVal)
5254
}
5355
return ret
5456
}

ledger/shelley.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ func (b *ShelleyBlock) Era() Era {
4848
func (b *ShelleyBlock) Transactions() []TransactionBody {
4949
ret := []TransactionBody{}
5050
for _, v := range b.TransactionBodies {
51-
ret = append(ret, &v)
51+
// Create temp var since we take the address and the loop var gets reused
52+
tmpVal := v
53+
ret = append(ret, &tmpVal)
5254
}
5355
return ret
5456
}

0 commit comments

Comments
 (0)