diff --git a/src/mem/largealloc.h b/src/mem/largealloc.h index 8f91440f..f7fcc921 100644 --- a/src/mem/largealloc.h +++ b/src/mem/largealloc.h @@ -294,7 +294,14 @@ namespace snmalloc template bool reserve_memory(size_t need, size_t add) { - if ((address_cast(reserved_start) + need) > address_cast(reserved_end)) + assert(reserved_start <= reserved_end); + + /* + * Spell this comparison in terms of pointer subtraction like this, + * rather than "reserved_start + need < reserved_end" because the + * sum might not be representable on CHERI. + */ + if (pointer_diff(reserved_start, reserved_end) < need) { if constexpr (allow_reserve == YesReserve) {