Make sure aligned_alloc args are valid

This commit is contained in:
2025-08-15 14:14:55 -04:00
parent abea5cd8cd
commit 3a508602f5

View File

@@ -93,7 +93,8 @@ private:
* @throws std::bad_alloc if memory allocation fails * @throws std::bad_alloc if memory allocation fails
*/ */
static Block *create(size_t size, Block *prev) { static Block *create(size_t size, Block *prev) {
void *memory = std::aligned_alloc(alignof(Block), sizeof(Block) + size); void *memory = std::aligned_alloc(
alignof(Block), align_up(sizeof(Block) + size, alignof(Block)));
if (!memory) { if (!memory) {
throw std::bad_alloc(); throw std::bad_alloc();
} }