From d9daeae38480689c12e026998755c1880c6efa42 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Thu, 29 Dec 2022 20:53:24 +0000 Subject: [PATCH] Fixed an arithmetic bug causing reserved memory regions at address 0x00 to be ignored --- sandbox/memblock/memblock.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sandbox/memblock/memblock.c b/sandbox/memblock/memblock.c index 789c072..abb6968 100644 --- a/sandbox/memblock/memblock.c +++ b/sandbox/memblock/memblock.c @@ -192,7 +192,12 @@ void __next_memory_region(memblock_iter_t *it, memblock_type_t *type_a, memblock * if we have gone past the last reserved region, these variables delimit the range between the end * of the last reserved region and the end of memory. */ uintptr_t r_start = idx_b > 0 ? r[-1].limit + 1 : 0; - uintptr_t r_end = idx_b < type_b->count ? r->base - 1 : ADDR_MAX; + uintptr_t r_end = idx_b < type_b->count ? r->base : ADDR_MAX; + + if (r_start == r_end) { + /* this free region has a length of zero, move to the next one */ + continue; + } if (r_start >= m_end) { /* we've gone past the end of the current memory region, and need to go to the next one */