-
-
Notifications
You must be signed in to change notification settings - Fork 3
Potential UB returning mutable bytes as MemoryBlock #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
As |
The |
From the current
It's not mentioned there directly. Even if it would be mentioned, I think this still holds as there is no bit pattern, which is undefined for |
If this is UB in any way, I'm fine with changing the signature of let mut data = [0; 64];
let mut alloc = Region::new(&mut data); vs let mut data = [0; 64];
let mut alloc = Region::new(data.as_mut_ptr(), data.len());
// make sure you don't use `data`, as `Region` don't have a lifetime bound anymore |
Not yet clear, as quoted above (rust-lang/unsafe-code-guidelines#71)
And in particular must not contain any uninitialized bytes (nit: if non-empty). It is safe to dereference a slice reference and do something like |
Okay, I now understand you point I guess, sry for taking so long 😄 I skimmed your linked issue. I think a good solution in any case (allowed or not) would be using |
alloc-compose/src/region.rs
Lines 86 to 96 in 375d762
These lines return part of the
data
as aMemoryBlock
. This unsafe operation permits the caller to write uninitialized bytes to that region. It's not yet clear if it is UB to do that. In any case it is a safety invariant so you mustn't leak this uninitialized state after your borrow ofdata
has ended but there is no Drop implementation that would take care of it.The text was updated successfully, but these errors were encountered: