Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Suppress compiler warning on potential buffer overflow #935

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

doctorlai-msrc
Copy link
Contributor

@doctorlai-msrc doctorlai-msrc commented Aug 31, 2024

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)

@doctorlai-msrc doctorlai-msrc marked this pull request as ready for review August 31, 2024 20:01
@doctorlai-msrc doctorlai-msrc changed the title Fix potential buffer overflow warning Suppress compiler warning on potential buffer overflow Aug 31, 2024
daanx added a commit that referenced this pull request Dec 30, 2024
@daanx
Copy link
Collaborator

daanx commented Dec 30, 2024

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)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants