File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -189,13 +189,18 @@ class Block {
189
189
190
190
// / @returns A pointer to the usable space inside this block.
191
191
// /
192
- // / Unless specifically requested otherwise, this will be aligned to
193
- // / max_align_t.
192
+ // / Aligned to some multiple of max_align_t.
194
193
LIBC_INLINE cpp::byte *usable_space () {
195
- return reinterpret_cast <cpp::byte *>(this ) + BLOCK_OVERHEAD;
194
+ auto *s = reinterpret_cast <cpp::byte *>(this ) + BLOCK_OVERHEAD;
195
+ LIBC_ASSERT (reinterpret_cast <uintptr_t >(s) % alignof (max_align_t ) == 0 &&
196
+ " usable space must be aligned to a multiple of max_align_t" );
197
+ return s;
196
198
}
197
199
LIBC_INLINE const cpp::byte *usable_space () const {
198
- return reinterpret_cast <const cpp::byte *>(this ) + BLOCK_OVERHEAD;
200
+ const auto *s = reinterpret_cast <const cpp::byte *>(this ) + BLOCK_OVERHEAD;
201
+ LIBC_ASSERT (reinterpret_cast <uintptr_t >(s) % alignof (max_align_t ) == 0 &&
202
+ " usable space must be aligned to a multiple of max_align_t" );
203
+ return s;
199
204
}
200
205
201
206
// @returns The region of memory the block manages, including the header.
@@ -455,6 +460,9 @@ optional<Block *> Block::split(size_t new_inner_size,
455
460
Block *new_block = as_block (new_region);
456
461
mark_free (); // Free status for this block is now stored in new_block.
457
462
new_block->next ()->prev_ = new_region.size ();
463
+
464
+ LIBC_ASSERT (new_block->is_usable_space_aligned (usable_space_alignment) &&
465
+ " usable space must have requested alignment" );
458
466
return new_block;
459
467
}
460
468
You can’t perform that action at this time.
0 commit comments