fix segfault that could be caused by merging an empty bloom-filter

with a bloom-filter already containing values.

I assume that it is ok to merge an empty bloom-filter with any bloom-filter -
if not we have to change the patch to return an error in this case.
This commit is contained in:
Bernhard Amann 2013-07-30 16:10:06 -07:00
parent af9e181731
commit edb04e6d8b
4 changed files with 14 additions and 2 deletions

View file

@ -591,7 +591,10 @@ bool BloomFilterVal::Empty() const
BloomFilterVal* BloomFilterVal::Merge(const BloomFilterVal* x,
const BloomFilterVal* y)
{
if ( ! same_type(x->Type(), y->Type()) )
if ( ( x->Type() != y->Type() ) && // both 0 is ok
( x->Type() != 0 ) && // any one 0 also is ok
( y->Type() != 0 ) &&
! same_type(x->Type(), y->Type()) )
{
reporter->Error("cannot merge Bloom filters with different types");
return 0;

View file

@ -186,7 +186,10 @@ function bloomfilter_merge%(bf1: opaque of bloomfilter,
const BloomFilterVal* bfv1 = static_cast<const BloomFilterVal*>(bf1);
const BloomFilterVal* bfv2 = static_cast<const BloomFilterVal*>(bf2);
if ( ! same_type(bfv1->Type(), bfv2->Type()) )
if ( ( bfv1->Type() != bfv2->Type() ) && // both 0 is ok
(bfv1->Type() != 0) &&
(bfv2->Type() != 0) &&
! same_type(bfv1->Type(), bfv2->Type()) )
{
reporter->Error("incompatible Bloom filter types");
return 0;

View file

@ -17,6 +17,7 @@ error: false-positive rate must take value between 0 and 1
1
1
1
1
2
3
3

View file

@ -45,6 +45,11 @@ function test_basic_bloom_filter()
print bloomfilter_lookup(bf_merged, 84);
print bloomfilter_lookup(bf_merged, 100);
print bloomfilter_lookup(bf_merged, 168);
#empty filter tests
local bf_empty = bloomfilter_basic_init(0.1, 1000);
local bf_empty_merged = bloomfilter_merge(bf_merged, bf_empty);
print bloomfilter_lookup(bf_empty_merged, 42);
}
function test_counting_bloom_filter()