[libc-commits] [libc] [libc] Fix malloc Block alignment issue on riscv32 (PR #117815)
via libc-commits
libc-commits at lists.llvm.org
Tue Jan 14 11:53:05 PST 2025
================
@@ -309,21 +322,30 @@ class Block {
Block *next;
};
- // Divide a block into up to 3 blocks according to `BlockInfo`. This should
- // only be called if `can_allocate` returns true.
+ // Divide a block into up to 3 blocks according to `BlockInfo`. Behavior is
+ // undefined if allocation is not possible for the given size and alignment.
static BlockInfo allocate(Block *block, size_t alignment, size_t size);
+ LIBC_INLINE static uintptr_t next_possible_block_start(
+ uintptr_t ptr, size_t usable_space_alignment = alignof(max_align_t)) {
+ return align_up(ptr + sizeof(Block), usable_space_alignment) -
----------------
PiJoules wrote:
I could be overthinking here, but is it possible for `ptr + sizeof(Block)` causing `next_possible_block_start` to also overflow? I imagine it's very unlikely, but I'm thinking it's possible through `Block::split` if `min_outer_size` is large enough there(?)
https://github.com/llvm/llvm-project/pull/117815
More information about the libc-commits
mailing list