diff --git a/src/avalanche.h b/src/avalanche.h --- a/src/avalanche.h +++ b/src/avalanche.h @@ -144,9 +144,14 @@ class AvalancheBlockUpdate { union { CBlockIndex *pindex; - size_t raw; + uintptr_t raw; }; + static const size_t BITS = 2; + static const uintptr_t MASK = (1 << BITS) - 1; + + static_assert(alignof(CBlockIndex) >= 1 << BITS); + public: enum Status : uint8_t { Invalid, @@ -160,10 +165,10 @@ raw |= statusIn; } - Status getStatus() const { return Status(raw & 0x03); } + Status getStatus() const { return Status(raw & MASK); } CBlockIndex *getBlockIndex() { - return reinterpret_cast(raw & -size_t(0x04)); + return reinterpret_cast(raw & ~MASK); } const CBlockIndex *getBlockIndex() const {