Skip to content

Commit b741a62

Browse files
committed
Merge bitcoin/bitcoin#27929: Added static_assert to check that base_blob is using whole bytes.
5fc4939 Added static_assert to check that base_blob is using whole bytes. (Brotcrunsher) Pull request description: Prior to this commit it was possible to create base_blobs with any arbitrary amount of bits, like base_blob<9>. One could assume that this would be a valid way to create a bit field that guarantees to have at least 9 bits. However, in such a case, base_blob would not behave as expected because the WIDTH is rounded down to the closest whole byte (simple integer division by 8). This commit makes sure that this oddity is detected and blocked by the compiler. ACKs for top commit: MarcoFalke: lgtm ACK 5fc4939 theStack: ACK 5fc4939 stickies-v: ACK 5fc4939 Tree-SHA512: 6a06760f09d4a9e6f0b9338d4dddd4091f2ac59a843a443d9302959936d72c55f7cccd55a51ec3a5a799921f68be1b87968ef3c9c11d3389cbd369b5045bb50a
2 parents 35b01e8 + 5fc4939 commit b741a62

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

Diff for: src/uint256.h

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class base_blob
2222
{
2323
protected:
2424
static constexpr int WIDTH = BITS / 8;
25+
static_assert(BITS % 8 == 0, "base_blob currently only supports whole bytes.");
2526
std::array<uint8_t, WIDTH> m_data;
2627
static_assert(WIDTH == sizeof(m_data), "Sanity check");
2728

0 commit comments

Comments
 (0)