From d3715132d165d8d1fefc66f3414acb897502c4fd Mon Sep 17 00:00:00 2001 From: Daan Date: Sun, 6 Nov 2022 09:52:54 -0800 Subject: [PATCH] move null ptr check --- include/mimalloc-internal.h | 3 +-- src/alloc.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/include/mimalloc-internal.h b/include/mimalloc-internal.h index 6b4b86a2..4620fb72 100644 --- a/include/mimalloc-internal.h +++ b/include/mimalloc-internal.h @@ -426,8 +426,7 @@ static inline mi_page_t* _mi_get_free_small_page(size_t size) { // Segment that contains the pointer static inline mi_segment_t* _mi_ptr_segment(const void* p) { - // mi_assert_internal(p != NULL); - if (p == NULL) return NULL; + mi_assert_internal(p != NULL); return (mi_segment_t*)(((uintptr_t)p - 1) & ~MI_SEGMENT_MASK); } diff --git a/src/alloc.c b/src/alloc.c index 9ecb9f30..d10bd586 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -470,8 +470,8 @@ static inline mi_segment_t* mi_checked_ptr_segment(const void* p, const char* ms } #endif + if mi_unlikely(p == NULL) return NULL; mi_segment_t* const segment = _mi_ptr_segment(p); - if mi_unlikely(segment == NULL) return NULL; // checks also for (p==NULL) #if (MI_DEBUG>0) if mi_unlikely(!mi_is_in_heap_region(p)) {