Skip to content
MISRA_HEAP_ALLOCATOR_MAGIC

MISRA_HEAP_ALLOCATOR_MAGIC

Description

Per-type magic for HeapAllocator. Stamped into Allocator.base.__magic by HeapAllocatorInit*. The heap implementation functions (heap_allocator_allocate / ..._reallocate / ..._deallocate) validate this exact value, so passing a PageAllocator / ArenaAllocator / PoolAllocator through a HeapAllocator * cast is caught at runtime as type-confusion instead of silently corrupting memory.

Usage example (Cross-references)

Usage examples (Cross-references)
    
    static void heap_validate_self(const Allocator *self) {
        if (!self || self->__magic != MISRA_HEAP_ALLOCATOR_MAGIC) {
            LOG_FATAL("type-confusion: allocator passed to heap_allocator_* is not a HeapAllocator");
        }
                       .effort      = ALLOCATOR_EFFORT_ONCE,                                                                     \
                       .retry_limit = 0,                                                                                         \
                       .__magic     = MISRA_HEAP_ALLOCATOR_MAGIC},                                                                   \
            .bins        = {0},                                                                                            \
            .chunks_head = NULL,                                                                                           \
                       .effort      = ALLOCATOR_EFFORT_ONCE,                                                                     \
                       .retry_limit = 0,                                                                                         \
                       .__magic     = MISRA_HEAP_ALLOCATOR_MAGIC},                                                                   \
            .bins        = {0},                                                                                            \
            .chunks_head = NULL,                                                                                           \
Last updated on