From 4cb5b45178835c9df706194edf837d02a64efc6f Mon Sep 17 00:00:00 2001 From: daanx Date: Fri, 21 Apr 2023 09:37:05 -0700 Subject: [PATCH] fix possible underflow (issue #731) --- src/segment.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/segment.c b/src/segment.c index 41c28065..359bd258 100644 --- a/src/segment.c +++ b/src/segment.c @@ -1273,9 +1273,12 @@ void _mi_segment_huge_page_reset(mi_segment_t* segment, mi_page_t* page, mi_bloc mi_assert_internal(page->used == 1); // this is called just before the free mi_assert_internal(page->free == NULL); if (segment->allow_decommit && page->is_committed) { - const size_t usize = mi_usable_size(block) - sizeof(mi_block_t); - uint8_t* p = (uint8_t*)block + sizeof(mi_block_t); - _mi_os_reset(p, usize, &_mi_stats_main); + size_t usize = mi_usable_size(block); + if (usize > sizeof(mi_block_t)) { + usize = usize - sizeof(mi_block_t); + uint8_t* p = (uint8_t*)block + sizeof(mi_block_t); + _mi_os_reset(p, usize, &_mi_stats_main); + } } } #endif