-
Notifications
You must be signed in to change notification settings - Fork 39
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
Incorrect use of assume_init #34
Comments
Thanks for point out! I refine the code. Line 32 in 9f45261
|
That depends on the And it seems like this function is publicly exposed through a macro, so a user could use this in a way that it returns a It is correct when |
In fact given that |
The For the |
It doesn't matter if the value is ever returned to the user. What matters is that the value is even constructed. So the only way this is okay is if that code is never executed. In that case, I suggest you remove the The following code is wrong: fn done_and_forget<T>() {
let ret = std::mem::MaybeUninit::uninit();
mem::forget::<T>(unsafe { ret.assume_init() });
} I think this roughly corresponds to what your code is doing, and hence, that code is also wrong. It is clearly documented as wrong in the documentation of
"immediate" means exactly that -- immediate. There is no exception for "the next thing we do is You can also see this by running this example code: it panics, because it executes a wrong |
I see, thanks for the example! |
I think this could be closed |
I noticed by coincidence some incorrect uses of assume_init in this crate:
generator-rs/src/yield_.rs
Line 32 in 9f45261
generator-rs/src/stack/unix.rs
Line 97 in cd677f7
Quoting from the
assume_init
docs (emphasis mine):It does not matter whether the value is dropped, or never used, or anything like that. Calling
assume_init
when the data is not yet initialized is a safety violation in all cases.getrlimit
is easy to fix, it should useMaybeUninit::as_mut_ptr
. The other function looks very suspicious but I do not understand enough of what is going on to suggest a fix.(The other two uses of
assume_init
in this crate also look suspicious, but I can't tell where the values are coming from -- they sure look like they have not actually been properly initialized yet, though.)The text was updated successfully, but these errors were encountered: