Skip to content

Commit 82c3b3f

Browse files
Remove sharp edge (uninitialized m_filter_type) when using the compiler-generated constructor for BlockFilter
1 parent 2d46f1b commit 82c3b3f

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/blockfilter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ bool BlockFilter::BuildParams(GCSFilter::Params& params) const
251251
params.m_P = BASIC_FILTER_P;
252252
params.m_M = BASIC_FILTER_M;
253253
return true;
254+
case BlockFilterType::INVALID:
255+
return false;
254256
}
255257

256258
return false;

src/blockfilter.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ class GCSFilter
8383
constexpr uint8_t BASIC_FILTER_P = 19;
8484
constexpr uint32_t BASIC_FILTER_M = 784931;
8585

86-
enum BlockFilterType : uint8_t
86+
enum class BlockFilterType : uint8_t
8787
{
8888
BASIC = 0,
89+
INVALID = 255,
8990
};
9091

9192
/**
@@ -95,7 +96,7 @@ enum BlockFilterType : uint8_t
9596
class BlockFilter
9697
{
9798
private:
98-
BlockFilterType m_filter_type;
99+
BlockFilterType m_filter_type = BlockFilterType::INVALID;
99100
uint256 m_block_hash;
100101
GCSFilter m_filter;
101102

src/test/blockfilter_tests.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ BOOST_AUTO_TEST_CASE(blockfilter_basic_test)
112112
BOOST_CHECK_EQUAL(block_filter.GetFilterType(), block_filter2.GetFilterType());
113113
BOOST_CHECK_EQUAL(block_filter.GetBlockHash(), block_filter2.GetBlockHash());
114114
BOOST_CHECK(block_filter.GetEncodedFilter() == block_filter2.GetEncodedFilter());
115+
116+
BlockFilter default_ctor_block_filter_1;
117+
BlockFilter default_ctor_block_filter_2;
118+
BOOST_CHECK_EQUAL(default_ctor_block_filter_1.GetFilterType(), default_ctor_block_filter_2.GetFilterType());
119+
BOOST_CHECK_EQUAL(default_ctor_block_filter_1.GetBlockHash(), default_ctor_block_filter_2.GetBlockHash());
120+
BOOST_CHECK(default_ctor_block_filter_1.GetEncodedFilter() == default_ctor_block_filter_2.GetEncodedFilter());
115121
}
116122

117123
BOOST_AUTO_TEST_CASE(blockfilters_json_test)

0 commit comments

Comments
 (0)