mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-21 08:51:32 +00:00
common: fix BitArray.Update to avoid nil dereference
Update previously only checked that the receiver was
non-nil but didn't check that the input parameter to update
"o" was non-nil causing a nil dereference in cases such as
fe632ea32a/consensus/reactor.go (L306)
Fixes https://github.com/tendermint/tendermint/issues/1169
This commit is contained in:
@ -164,3 +164,26 @@ func TestEmptyFull(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateNeverPanics(t *testing.T) {
|
||||
newRandBitArray := func(n int) *BitArray {
|
||||
ba, _ := randBitArray(n)
|
||||
return ba
|
||||
}
|
||||
pairs := []struct {
|
||||
a, b *BitArray
|
||||
}{
|
||||
{nil, nil},
|
||||
{newRandBitArray(10), newRandBitArray(12)},
|
||||
{newRandBitArray(0), NewBitArray(10)},
|
||||
{nil, NewBitArray(10)},
|
||||
{nil, newRandBitArray(64)},
|
||||
{newRandBitArray(63), newRandBitArray(64)},
|
||||
}
|
||||
|
||||
for _, pair := range pairs {
|
||||
a, b := pair.a, pair.b
|
||||
a.Update(b)
|
||||
b.Update(a)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user