Open
Description
These methods take &mut [AlignedType]
which must be initialized because it does not contain MaybeUninit
. The API may entice people to write this code though:
unsafe {
let buffer = allocator.alloc(size, alignment); // returns uninitialized data
let buffer = core::slice::from_raw_parts(buffer, size);
Secp256k1::preallocated_new(buffer)
}
This is unsound and it's not obvious. (The whole maybe uninit business is subtle and not widely understood by people.)
I was thinking about making it accept &mut [MaybeUninit<AlignedType>]
but that may be annoying for consumers and promotes casting &mut T
to &mut MaybeUninit<T>
which, while not unsound itself, needs to be treated carefully. So the only sane option that I can think of is defining AlignedType
as struct AlignedType(MaybeUninit<[u8, 16]>)
, providing conversions from pointers/MaybeUninit<[AlignedType]>
and documenting that it's fine to have it uninitialized.
Metadata
Metadata
Assignees
Labels
No labels