News for hackers. Stuff that matters.
Re:Always Bump Downwards (2019) by ridiculous_fish on Tuesday September 19, 2023 @01:42PM (#37573435)
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.
Re:Always Bump Downwards (2019) by loeg on Tuesday September 19, 2023 @02:34PM (#37574168)
The straightforward answer is: don't tolerate ridiculous alignments.
Re:Always Bump Downwards (2019) by saagarjha on Tuesday September 19, 2023 @08:39PM (#37579042)
You'd need to check for that, though.
Re:Always Bump Downwards (2019) by loeg on Tuesday September 19, 2023 @11:16PM (#37580029)
No, just restrict the domain of the alignment input to like, u8. Maybe u16. Either way, it is easy to ensure your bump allocation space is far enough away from SIZE_MAX.
Re:Always Bump Downwards (2019) by dev_dwarf on Tuesday September 19, 2023 @02:03PM (#37573754)
Interesting 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

Update: NVM, definitely not being handled correctly. https://godbolt.org/z/cMTe1o979