Skip to content

Commit f0e2286

Browse files
committed
Catch calls to initialize an oversize heap
1 parent ed68d0b commit f0e2286

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

src/umm_malloc.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,21 @@ static uint16_t umm_assimilate_down(umm_heap *heap, uint16_t c, uint16_t freemas
278278
/* ------------------------------------------------------------------------- */
279279

280280
void umm_multi_init_heap(umm_heap *heap, void *ptr, size_t size) {
281+
/* Guard against too many blocks for 15-bit indices */
282+
if ((size / UMM_BLOCKSIZE) > UMM_BLOCKNO_MASK)
283+
{
284+
/* Try increasing UMM_BLOCKSIZE if this hits */
285+
DBGLOG_CRITICAL("Heap too large: %u blocks (max %u)\n",
286+
(unsigned) UMM_NUMBLOCKS, (unsigned) UMM_BLOCKNO_MASK);
287+
288+
/* Mark this heap as unusable */
289+
heap->pheap = NULL;
290+
UMM_HEAPSIZE = 0;
291+
UMM_NUMBLOCKS = 0;
292+
293+
return;
294+
}
295+
281296
/* init heap pointer and size, and memset it to 0 */
282297
heap->pheap = ptr;
283298
UMM_HEAPSIZE = size;
@@ -799,4 +814,4 @@ void *umm_realloc(void *ptr, size_t size){
799814

800815
void umm_free(void *ptr){
801816
umm_multi_free(&umm_heap_current, ptr);
802-
}
817+
}

0 commit comments

Comments
 (0)