Skip to content

fix(memory): ArenaAllocator::Allocate missing explicit power-of-two alignment precondition #680

Description

@JeanPhilippeKernel

Summary

ArenaAllocator::Allocate(size_t size, size_t alignment) has no explicit assertion that alignment is a power of two before calling memory_align().

Location

ZEngine/ZEngine/Core/Memory/Allocator.cpp:60ArenaAllocator::Allocate

Detail

The power-of-two assertion exists inside Helpers::memory_align() (MemoryOperations.h:172):

ZENGINE_VALIDATE_ASSERT(is_power_of_two(align), "Alignment should be power of two");

And Resize() adds its own explicit assert at Allocator.cpp:112:

ZENGINE_VALIDATE_ASSERT(Helpers::is_power_of_two(alignment), "Alignment should be power of 2")

But Allocate() has no such guard at the call site. Defensive programming should assert the precondition directly in Allocate() before delegating to the helper — consistent with how Resize() handles it.

Fix

Add at the top of Allocate():

ZENGINE_VALIDATE_ASSERT(Helpers::is_power_of_two(alignment), "ArenaAllocator::Allocate: alignment must be a power of two");

Impact

Low — the assertion fires inside memory_align() regardless, so no allocation with a bad alignment succeeds silently. This is a defensive programming / consistency gap, not a silent failure.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions