aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2019-03-08 15:26:15 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2019-03-08 15:26:28 +0100
commitefed9809b4fab34e33c3012aa3cf4b7a75d98ead (patch)
tree2655f7877f99007ea124cf68f42399e0117343a3 /src
parent923d87497c7ce730259ba9a5c0419a0baca77aeb (diff)
parent82c3b3f8e07f0572327275841333256fa3e679e3 (diff)
downloadbitcoin-efed9809b4fab34e33c3012aa3cf4b7a75d98ead.tar.xz
Merge #15532: Remove sharp edge (uninit member) when using the compiler-generated ctor for BlockFilter
82c3b3f8e07f0572327275841333256fa3e679e3 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
Diffstat (limited to 'src')
-rw-r--r--src/blockfilter.cpp2
-rw-r--r--src/blockfilter.h5
-rw-r--r--src/test/blockfilter_tests.cpp6
3 files changed, 11 insertions, 2 deletions
diff --git a/src/blockfilter.cpp b/src/blockfilter.cpp
index bcf24047ff..e15213c552 100644
--- a/src/blockfilter.cpp
+++ b/src/blockfilter.cpp
@@ -251,6 +251,8 @@ bool BlockFilter::BuildParams(GCSFilter::Params& params) const
params.m_P = BASIC_FILTER_P;
params.m_M = BASIC_FILTER_M;
return true;
+ case BlockFilterType::INVALID:
+ return false;
}
return false;
diff --git a/src/blockfilter.h b/src/blockfilter.h
index 4d1f51dd60..e5e087ed5a 100644
--- a/src/blockfilter.h
+++ b/src/blockfilter.h
@@ -83,9 +83,10 @@ public:
constexpr uint8_t BASIC_FILTER_P = 19;
constexpr uint32_t BASIC_FILTER_M = 784931;
-enum BlockFilterType : uint8_t
+enum class BlockFilterType : uint8_t
{
BASIC = 0,
+ INVALID = 255,
};
/**
@@ -95,7 +96,7 @@ enum BlockFilterType : uint8_t
class BlockFilter
{
private:
- BlockFilterType m_filter_type;
+ BlockFilterType m_filter_type = BlockFilterType::INVALID;
uint256 m_block_hash;
GCSFilter m_filter;
diff --git a/src/test/blockfilter_tests.cpp b/src/test/blockfilter_tests.cpp
index 625362f446..cd0c36d802 100644
--- a/src/test/blockfilter_tests.cpp
+++ b/src/test/blockfilter_tests.cpp
@@ -112,6 +112,12 @@ BOOST_AUTO_TEST_CASE(blockfilter_basic_test)
BOOST_CHECK_EQUAL(block_filter.GetFilterType(), block_filter2.GetFilterType());
BOOST_CHECK_EQUAL(block_filter.GetBlockHash(), block_filter2.GetBlockHash());
BOOST_CHECK(block_filter.GetEncodedFilter() == block_filter2.GetEncodedFilter());
+
+ BlockFilter default_ctor_block_filter_1;
+ BlockFilter default_ctor_block_filter_2;
+ BOOST_CHECK_EQUAL(default_ctor_block_filter_1.GetFilterType(), default_ctor_block_filter_2.GetFilterType());
+ BOOST_CHECK_EQUAL(default_ctor_block_filter_1.GetBlockHash(), default_ctor_block_filter_2.GetBlockHash());
+ BOOST_CHECK(default_ctor_block_filter_1.GetEncodedFilter() == default_ctor_block_filter_2.GetEncodedFilter());
}
BOOST_AUTO_TEST_CASE(blockfilters_json_test)