5 ms·
I think this doesn't work because `aligned + size` may wrap all the way around into the valid region again. For example if aligned == ptr + 1, and size is usize
by ridiculous_fish 3y ago
I think this doesn't work because `aligned + size` may wrap all the way around into the valid region again. For example if aligned == ptr + 1, and size is usize::MAX, we will end up with new_ptr == ptr and the allocation will wrongly succeed.
- loeg 3y agoThe straightforward answer is: don't tolerate ridiculous alignments.
- dev_dwarf 3y agoInteresting point. I modified my example to test what you described. I had to play with the compilation flags to get the allocs to not be optimized out and to not panic when the integer overflow happens, but otherwise I didn't change the logic. I'm pretty sure my implementation is correctly handling the case you mention, evidenced by it returning a null pointer. Link: https://godbolt.org/z/f1jGW6Pa3 https://godbolt.org/z/f1jGW6Pa3 Update: NVM, definitely not being handled correctly. https://godbolt.org/z/cMTe1o979 https://godbolt.org/z/cMTe1o979
- deleted 3y ago[deleted]