Skip to content

Commit efed980

Browse files
committed
Merge #15532: Remove sharp edge (uninit member) when using the compiler-generated ctor for BlockFilter
82c3b3f Remove sharp edge (uninitialized m_filter_type) when using the compiler-generated constructor for BlockFilter (practicalswift) Pull request description: Remove sharp edge (uninitialised member `m_filter_type`) when using the compiler-generated constructor for `BlockFilter`. Before (but after added test): ``` $ src/test/test_bitcoin -t blockfilter_tests/blockfilter_basic_test Running 1 test case... test/blockfilter_tests.cpp(118): error: in "blockfilter_tests/blockfilter_basic_test": check default_ctor_block_filter_1.GetFilterType() == default_ctor_block_filter_2.GetFilterType() has failed [ != ] *** 1 failure is detected in the test module "Bitcoin Test Suite" ``` After: ``` $ src/test/test_bitcoin -t blockfilter_tests/blockfilter_basic_test Running 1 test case... *** No errors detected ``` Tree-SHA512: 21d41f036b0bf12adcf1a788d84747353f2023cb85fd8ea6c97222967032e8bf54e7910cadb45dfcecd78e5b5dca86685f78cad0596b6d1a08f910ebf20d90aa
2 parents 923d874 + 82c3b3f commit efed980

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)