Merge remote-tracking branch 'origin/fastpath'

Slightly adapted after discussing with Bernhard. I also added one
further check.

* origin/fastpath:
  fix segfault that could be caused by merging an empty bloom-filter with a bloom-filter already containing values.
This commit is contained in:
Robin Sommer 2013-07-31 20:08:28 -07:00
commit 86dcea3b35
6 changed files with 19 additions and 4 deletions

View file

@ -1,4 +1,9 @@
2.1-948 | 2013-07-31 20:08:28 -0700
* Fix segfault caused by merging an empty bloom-filter with a
bloom-filter already containing values. (Bernhard Amann)
2.1-945 | 2013-07-30 10:05:10 -0700 2.1-945 | 2013-07-30 10:05:10 -0700
* Make hashers serializable. (Matthias Vallentin) * Make hashers serializable. (Matthias Vallentin)

View file

@ -1 +1 @@
2.1-945 2.1-948

View file

@ -591,7 +591,9 @@ bool BloomFilterVal::Empty() const
BloomFilterVal* BloomFilterVal::Merge(const BloomFilterVal* x, BloomFilterVal* BloomFilterVal::Merge(const BloomFilterVal* x,
const BloomFilterVal* y) const BloomFilterVal* y)
{ {
if ( ! same_type(x->Type(), y->Type()) ) if ( x->Type() && // any one 0 is ok here
y->Type() &&
! same_type(x->Type(), y->Type()) )
{ {
reporter->Error("cannot merge Bloom filters with different types"); reporter->Error("cannot merge Bloom filters with different types");
return 0; return 0;
@ -613,7 +615,7 @@ BloomFilterVal* BloomFilterVal::Merge(const BloomFilterVal* x,
BloomFilterVal* merged = new BloomFilterVal(copy); BloomFilterVal* merged = new BloomFilterVal(copy);
if ( ! merged->Typify(x->Type()) ) if ( x->Type() && ! merged->Typify(x->Type()) )
{ {
reporter->Error("failed to set type on merged Bloom filter"); reporter->Error("failed to set type on merged Bloom filter");
return 0; return 0;

View file

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

View file

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

View file

@ -45,6 +45,11 @@ function test_basic_bloom_filter()
print bloomfilter_lookup(bf_merged, 84); print bloomfilter_lookup(bf_merged, 84);
print bloomfilter_lookup(bf_merged, 100); print bloomfilter_lookup(bf_merged, 100);
print bloomfilter_lookup(bf_merged, 168); 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() function test_counting_bloom_filter()