diff --git a/src/avalanche.h b/src/avalanche.h --- a/src/avalanche.h +++ b/src/avalanche.h @@ -144,9 +144,16 @@ class AvalancheBlockUpdate { union { CBlockIndex *pindex; - size_t raw; + uintptr_t raw; }; + static const size_t STATUS_BITS = 2; + static const uintptr_t MASK = (1 << STATUS_BITS) - 1; + + static_assert( + alignof(CBlockIndex) >= (1 << STATUS_BITS), + "CBlockIndex alignement doesn't allow for Status to be stored."); + public: enum Status : uint8_t { Invalid, @@ -160,10 +167,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 {