mimalloc
mimalloc copied to clipboard
Suppress compiler warning on potential buffer overflow
The compiler gives the warning at (this issue):
error: '__atomic_load_8' writing 8 bytes into a region of size 0 overflows the destination [-Werror=stringop-overflow=]
In file included from /janus/3p/mimalloc/include/mimalloc/internal.h:17,
from /janus/3p/mimalloc/src/heap.c:9:
In function 'mi_heap_page_is_valid',
inlined from 'mi_heap_page_collect' at /janus/3p/mimalloc/src/heap.c:95:3:
/janus/3p/mimalloc/src/heap.c:62:22: error: '__atomic_load_8' writing 8 bytes into a region of size 0 overflows the destination [-Werror=stringop-overflow=]
62 | mi_assert_internal(segment->thread_id == heap->thread_id);
| ^~~~~~~
It is detecting a potential buffer overflow when accessing the thread_id in the segment structure. The warning suggests that the compiler believes the thread_id is being accessed in a way that could lead to reading or writing beyond the allocated memory of the structure.
This PR suppress this warning as I believe the code is safe (the false positive)
I think the warning is due to reading the atomic directly -- I added a mi_atomic_load_relaxed -- hopefully that fixes the warning? Let me know. (I am always hesitant to add compiler specific pragma's etc)