Closed
Description
The docs for Layout::from_size_align_unchecked
state that:
size
, when rounded up to the nearest multiple ofalign
, must not overflowisize
(i.e., the rounded value must be less than or equal toisize::MAX
)
alloc::realloc
's docs state a different constraint:
new_size
, when rounded up to the nearest multiple oflayout.align()
, must not overflow (i.e., the rounded value must be less thanusize::MAX
).
So this would be legal according to alloc::realloc
's docs:
let layout = alloc::Layout::from_size_align(1, 1);
let ptr1 = alloc::alloc(layout);
let ptr2 = alloc::realloc(ptr1, layout, usize::MAX);
But this results in a call internally:
Layout::from_size_align_unchecked(usize::MAX, 1)
...which is meant to be UB.
I assume this is just that the docs are out of date after #95295.