mirror of
https://github.com/ToyB-Chan/minimal-heap.git
synced 2026-07-13 21:51:16 +02:00
fixed allocations with sizes smaller than the max area limited but bigger than the max payload size never return
This commit is contained in:
@@ -189,6 +189,7 @@ void MIHP_ValidateHeapMemoryAreaHeader(const MIHP_Heap* heap, const MIHP_HeapMem
|
|||||||
void MIHP_ValidateHeapSegmentHeader(const MIHP_Heap* heap, const MIHP_HeapSegmentHeader* segment);
|
void MIHP_ValidateHeapSegmentHeader(const MIHP_Heap* heap, const MIHP_HeapSegmentHeader* segment);
|
||||||
|
|
||||||
size_t MIHP_GetMinimalPayloadSize(const MIHP_Heap* heap);
|
size_t MIHP_GetMinimalPayloadSize(const MIHP_Heap* heap);
|
||||||
|
size_t MIHP_GetMaximalPayloadSize(const MIHP_Heap* heap);
|
||||||
/* */
|
/* */
|
||||||
|
|
||||||
#if MIHP_IMPLEMENTATION
|
#if MIHP_IMPLEMENTATION
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include "minimal_heap.h"
|
||||||
#define MIHP_MIN(A, B) ((A) < (B) ? (A) : (B))
|
#define MIHP_MIN(A, B) ((A) < (B) ? (A) : (B))
|
||||||
#define MIHP_MAX(A, B) ((A) > (B) ? (A) : (B))
|
#define MIHP_MAX(A, B) ((A) > (B) ? (A) : (B))
|
||||||
|
|
||||||
@@ -117,7 +118,7 @@ void* MIHP_Allocate(MIHP_Heap* heap, size_t size)
|
|||||||
if (size == 0)
|
if (size == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (size > heap->Config.MaxMemoryAreaSize)
|
if (size > MIHP_GetMaximalPayloadSize(heap))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
MIHP_LockHeap(heap);
|
MIHP_LockHeap(heap);
|
||||||
@@ -871,3 +872,11 @@ size_t MIHP_GetMinimalPayloadSize(const MIHP_Heap* heap)
|
|||||||
{
|
{
|
||||||
return MIHP_MAX(sizeof(MIHP_HeapSegmentHeader), heap->Config.AllocationAlignment);
|
return MIHP_MAX(sizeof(MIHP_HeapSegmentHeader), heap->Config.AllocationAlignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline size_t MIHP_GetMaximalPayloadSize(const MIHP_Heap* heap)
|
||||||
|
{
|
||||||
|
size_t maxPayloadSize = heap->Config.MaxMemoryAreaSize;
|
||||||
|
maxPayloadSize -= MIHP_GetHeapAlignedSize(heap, sizeof(_MIHP_HeapMemoryAreaHeader));
|
||||||
|
maxPayloadSize -= MIHP_GetHeapAlignedSize(heap, sizeof(MIHP_HeapSegmentHeader));
|
||||||
|
return maxPayloadSize;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user