From 13490948d13530b10b81deb803a2c94d41f05a2b Mon Sep 17 00:00:00 2001 From: Zhihua Lai Date: Sat, 31 Aug 2024 20:47:37 +0100 Subject: [PATCH 1/3] Fix potential buffer overflow warning --- src/heap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/heap.c b/src/heap.c index a3aaaf6b5..58f006e33 100644 --- a/src/heap.c +++ b/src/heap.c @@ -59,7 +59,8 @@ static bool mi_heap_page_is_valid(mi_heap_t* heap, mi_page_queue_t* pq, mi_page_ MI_UNUSED(pq); mi_assert_internal(mi_page_heap(page) == heap); mi_segment_t* segment = _mi_page_segment(page); - mi_assert_internal(segment->thread_id == heap->thread_id); + uintptr_t thread_id = __atomic_load_n(&segment->thread_id, __ATOMIC_RELAXED); + mi_assert_internal(thread_id == heap->thread_id); mi_assert_expensive(_mi_page_is_valid(page)); return true; } From 74e5af47662d2e47a1658205e3d1609d4d7907a3 Mon Sep 17 00:00:00 2001 From: Zhihua Lai Date: Sat, 31 Aug 2024 20:54:15 +0100 Subject: [PATCH 2/3] Fix --- src/heap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/heap.c b/src/heap.c index 58f006e33..38f24efe4 100644 --- a/src/heap.c +++ b/src/heap.c @@ -59,7 +59,7 @@ static bool mi_heap_page_is_valid(mi_heap_t* heap, mi_page_queue_t* pq, mi_page_ MI_UNUSED(pq); mi_assert_internal(mi_page_heap(page) == heap); mi_segment_t* segment = _mi_page_segment(page); - uintptr_t thread_id = __atomic_load_n(&segment->thread_id, __ATOMIC_RELAXED); + mi_threadid_t thread_id = atomic_load(&segment->thread_id); mi_assert_internal(thread_id == heap->thread_id); mi_assert_expensive(_mi_page_is_valid(page)); return true; From 0ac3930ecf48d38395de66e1e3eb3a32559aadc6 Mon Sep 17 00:00:00 2001 From: Zhihua Lai Date: Sat, 31 Aug 2024 21:11:17 +0100 Subject: [PATCH 3/3] Suppress warning instead --- src/heap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/heap.c b/src/heap.c index 38f24efe4..344596554 100644 --- a/src/heap.c +++ b/src/heap.c @@ -59,8 +59,10 @@ static bool mi_heap_page_is_valid(mi_heap_t* heap, mi_page_queue_t* pq, mi_page_ MI_UNUSED(pq); mi_assert_internal(mi_page_heap(page) == heap); mi_segment_t* segment = _mi_page_segment(page); - mi_threadid_t thread_id = atomic_load(&segment->thread_id); - mi_assert_internal(thread_id == heap->thread_id); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-overflow" + mi_assert_internal(segment->thread_id == heap->thread_id); +#pragma GCC diagnostic pop mi_assert_expensive(_mi_page_is_valid(page)); return true; }