diff --git a/minimal_heap.h b/minimal_heap.h index cb59720..d7759b3 100644 --- a/minimal_heap.h +++ b/minimal_heap.h @@ -44,10 +44,10 @@ void MIHP_PlatformOnHeapCorruptionDetected(struct _MIHP_HeapCorruptionInfo info) typedef struct _MIHP_HeapConfig { - size_t AllocationAlignment; + size_t AllocationAlignment; // Must be power of two and at least sizeof(size_t) - size_t MinimalMemoryAreaSize; - size_t MaximalMemoryAreaSize; + size_t MinimalMemoryAreaSize; // Must be a multiple of AllocationAlingment + size_t MaximalMemoryAreaSize; // Must be a multiple of AllocationAlingment char AllocationInitialValue; } MIHP_HeapConfig; diff --git a/minimal_heap_implementation.inl b/minimal_heap_implementation.inl index 241783c..4438ee7 100644 --- a/minimal_heap_implementation.inl +++ b/minimal_heap_implementation.inl @@ -13,6 +13,12 @@ MIHP_Heap* MIHP_CreateHeap(MIHP_HeapConfig config) if (!MIHP_IS_PO2(config.AllocationAlignment)) return NULL; + if (config.MinimalMemoryAreaSize % config.AllocationAlignment != 0) + return NULL; + + if (config.MaximalMemoryAreaSize % config.AllocationAlignment != 0) + return NULL; + MIHP_Heap* heap = (MIHP_Heap*)MIHP_PlatformRequestMemory(sizeof(MIHP_Heap)); if (heap == NULL) return NULL;