github-vet / github-vet/rangeloop-pointer-findings
braveheart12/Ren-Hyperdrive: block/polka.go; 89 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [braveheart12/Ren-Hyperdrive](https://www.github.com/braveheart12/Ren-Hyperdrive) at [block/polka.go](https://github.com/braveheart12/Ren-Hyperdrive/blob/443a6567fa2094e6497df240febc26be0dfdae4c/block/polka.go#L283-L371)
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 round is reassigned at line 295
[Click here to see the code in its original context.](https://github.com/braveheart12/Ren-Hyperdrive/blob/443a6567fa2094e6497df240febc26be0dfdae4c/block/polka.go#L283-L371)
Click here to show the 89 line(s) of Go which triggered the analyzer.
```go
for round, preVotes := range preVotesByRound {
numNilPreVotes := 0
nilPreVoteSignatures := []sig.Signature{}
nilPreVoteSignatories := []sig.Signatory{}
if polka != nil && round <= polka.Round {
continue
}
if len(preVotes) < consensusThreshold {
continue
}
preVotesRound = &round
// Build a mapping of the pre-votes for each block
preVotesForBlock := map[sig.Hash]int{}
for _, preVote := range preVotes {
// Invariant check
if preVote.Height != height {
panic(fmt.Errorf("expected pre-vote height (%v) to equal %v", preVote.Height, height))
}
if preVote.Round != round {
panic(fmt.Errorf("expected pre-vote round (%v) to equal %v", preVote.Round, round))
}
if preVote.Block == nil {
numNilPreVotes++
nilPreVoteSignatures = append(nilPreVoteSignatures, preVote.Signature)
nilPreVoteSignatories = append(nilPreVoteSignatories, preVote.Signatory)
continue
}
// Invariant check
if preVote.Block.Height != height {
panic(fmt.Errorf("expected pre-vote block height (%v) to equal %v", preVote.Block.Height, height))
}
if preVote.Round != round {
panic(fmt.Errorf("expected pre-vote round (%v) to equal %v", preVote.Round, round))
}
preVotesForBlock[preVote.Block.Header]++
}
// Search for a polka of pre-votes for non-nil block
for blockHeader, numPreVotes := range preVotesForBlock {
if numPreVotes >= consensusThreshold {
polka = &Polka{
Signatures: make(sig.Signatures, 0, consensusThreshold),
Signatories: make(sig.Signatories, 0, consensusThreshold),
}
for _, preVote := range preVotes {
if preVote.Block != nil && preVote.Block.Header.Equal(blockHeader) {
if polka.Block != nil {
// Invariant check
if polka.Round != preVote.Round {
panic(fmt.Errorf("expected polka round (%v) to equal pre-vote round (%v)", polka.Round, preVote.Round))
}
if polka.Height != preVote.Height {
panic(fmt.Errorf("expected polka height (%v) to equal pre-vote height (%v)", polka.Height, preVote.Height))
}
} else {
// Invariant check
if preVote.Height != height {
panic(fmt.Errorf("expected pre-vote height (%v) to equal %v", preVote.Height, height))
}
if preVote.Round != round {
panic(fmt.Errorf("expected pre-vote round (%v) to equal %v", preVote.Round, round))
}
polka.Block = preVote.Block
polka.Round = preVote.Round
polka.Height = preVote.Height
}
polka.Signatures = append(polka.Signatures, preVote.Signature)
polka.Signatories = append(polka.Signatories, preVote.Signatory)
}
}
break
}
}
if numNilPreVotes >= consensusThreshold {
// Return a nil-Polka
polka = &Polka{
Block: nil,
Height: height,
Round: round,
Signatures: nilPreVoteSignatures,
Signatories: nilPreVoteSignatories,
}
}
}
```
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: 443a6567fa2094e6497df240febc26be0dfdae4c
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.