microsoft / snmalloc

Message passing based allocator
MIT License
1.58k stars 109 forks source link

0-length arrays in Buddy ranges #672

Closed nwf-msr closed 2 months ago

nwf-msr commented 2 months ago

Buddy ranges can be instantiated with MAX_SIZE_BITS == MIN_SIZE_BITS (or, in principle, <=). If this happens, the resulting class will contain 0-length arrays, and code that appears to attempt to access an element therein trips gcc's -Warray-bounds.

This PR contains two commits: one that adds a static_assert to ensure that Buddy's arrays are always of positive size, and one possible way to fix the case I'm tripping over. The latter works because the Buddy's MIN_SIZE_BITS is instantiated at MIN_CHUNK_BITS, and so the change herein then ensures that its MAX_SIZE_BITS is strictly greater than MIN_CHUNK_BITS.

A different, and possibly better, solution would be to drop the LargeBuddyRange from CentralMetaRange when max_page_chunk_size_bits is computed to be equal to MIN_CHUNK_BITS.

Please advise.

nwf commented 2 months ago

You OK to merge even though macos CI is still pending?

mjp41 commented 2 months ago

You OK to merge even though macos CI is still pending?

Yeah. I think Mac os 11 support has been removed. I think we need to remove and possibly add the next version