Let's say we have HeaderVec<u32, u8>::new(7u32)
. new
allocates an inital capacity of 1, so from the looks of things, that would get us an allocation layout of
alloc::alloc::Layout::from_size_align(
1, // Self::elems_to_mem_bytes(capacity),
4, // cmp::max(mem::align_of::<H>(), mem::align_of::<T>()),
)
Which, the documentation seems to suggest would round the allocation up to 4 bytes. This is only enough to store the header val. The remaining u8 in that the vector is supposed to be able to hold wouldn't actually be allocated for?
The problem is that the size of the memory layout has to be bigger than the capacity of the vec, but they're being treated as if they're the same.
This would only affect the last size_of::<H> - (size_of<T> % size_of<H>)
elements of the vec, or something like that, and I'd guess they'd often be kept protected from being messed with by other allocations by the allocator rounding up the allocation cell to contain more than is needed, so it's possible that the consequences of this have not been noticed yet.
I'll try to fix this... after lunch