github-vet / github-vet/rangeloop-pointer-findings
qiwitech/qdp: chain/chain.go; 50 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [qiwitech/qdp](https://www.github.com/qiwitech/qdp) at [chain/chain.go](https://github.com/qiwitech/qdp/blob/d82d2aa8fb16be0031c968201e4b492dd121d0d8/chain/chain.go#L119-L168)
Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first
issue it finds, so please do not limit your consideration to the contents of the below message.
> reference to txn is reassigned at line 164
[Click here to see the code in its original context.](https://github.com/qiwitech/qdp/blob/d82d2aa8fb16be0031c968201e4b492dd121d0d8/chain/chain.go#L119-L168)
Click here to show the 50 line(s) of Go which triggered the analyzer.
```go
for i, txn := range txns {
if txn.ID == 0 {
panic("chain put: zero txn id")
}
if txn.Sender != accID && txn.Receiver != accID {
panic("put to wrong chain")
}
if accID == txn.Sender { // it's output txn
e := list.GetOrInsert(txn.ID)
if e == nil {
panic("can't insert element")
}
if e.Value.Txn == nil {
e.Value.Txn = &txns[i]
} else if e.Value.Txn.SpentBy == 0 && txn.SpentBy != 0 {
e.Value.Txn.SpentBy = txn.SpentBy
}
}
if accID != txn.Receiver {
continue
}
// it's input txn
receiverTxnID := pt.NewTxnID(txn.Sender, txn.ID)
if txn.SpentBy == 0 { // it's unspent
_, ok := c.unspent[txn.Receiver]
if !ok {
unspent := make(map[pt.TxnID]*pt.Txn)
c.unspent[txn.Receiver] = unspent
}
c.unspent[txn.Receiver][receiverTxnID] = &txns[i]
continue
}
// it's spent input
e := list.GetOrInsert(txn.SpentBy)
if e == nil {
panic("can't insert element")
}
if e.Value.Inputs == nil {
e.Value.Inputs = make(map[pt.TxnID]*pt.Txn)
}
e.Value.Inputs[receiverTxnID] = &txn
// delete txn from unspent list
delete(c.unspent[txn.Receiver], receiverTxnID)
}
```
Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.
commit ID: d82d2aa8fb16be0031c968201e4b492dd121d0d8
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.