Skip to content

Commit c5e67be

Browse files
committed
Merge bitcoin/bitcoin#24032: Add defaults to vDeployments to avoid uninitialized variables
c4c5b9c consensus/params: set default values for BIP9Deployment (Anthony Towns) Pull request description: Adds default values for `vDeployments` in `consensus/params.h` so that undefined behaviour is avoided if a deployment is not initialized. Also adds a check in the unit tests to alert if this is happening, since even if it doesn't invoke undefined behaviour it's probably a mistake. ACKs for top commit: laanwj: Code review ACK c4c5b9c Tree-SHA512: 22d7ff86a817d9e9e67c47301fc3b7e9d5821c13565d7706711f113dea220eea29b413a7c8d029691009159cebc85a108d77cb52418734091c196bafb2b12423
2 parents a0e8aff + c4c5b9c commit c5e67be

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/consensus/params.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ constexpr bool ValidDeployment(DeploymentPos dep) { return dep < MAX_VERSION_BIT
4040
*/
4141
struct BIP9Deployment {
4242
/** Bit position to select the particular bit in nVersion. */
43-
int bit;
43+
int bit{28};
4444
/** Start MedianTime for version bits miner confirmation. Can be a date in the past */
45-
int64_t nStartTime;
45+
int64_t nStartTime{NEVER_ACTIVE};
4646
/** Timeout/expiry MedianTime for the deployment attempt. */
47-
int64_t nTimeout;
47+
int64_t nTimeout{NEVER_ACTIVE};
4848
/** If lock in occurs, delay activation until at least this block
4949
* height. Note that activation will only occur on a retarget
5050
* boundary.

src/test/versionbits_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ static void check_computeblockversion(VersionBitsCache& versionbitscache, const
273273
nStartTime == Consensus::BIP9Deployment::NEVER_ACTIVE)
274274
{
275275
BOOST_CHECK_EQUAL(min_activation_height, 0);
276+
BOOST_CHECK_EQUAL(nTimeout, Consensus::BIP9Deployment::NO_TIMEOUT);
276277
return;
277278
}
278279

0 commit comments

Comments
 (0)