Skip to content
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

unsafe use of pointer to object on stack #3

Closed
JakkuSakura opened this issue Oct 16, 2022 · 2 comments
Closed

unsafe use of pointer to object on stack #3

JakkuSakura opened this issue Oct 16, 2022 · 2 comments

Comments

@JakkuSakura
Copy link

JakkuSakura commented Oct 16, 2022

let mut sig = SyncSignal::new(&mut data as *mut T, std::thread::current());

Here data is taken pointer from, then forgotten. However, data is on stack, so it can be corrupted when being read again. Do you have justification for this?

In Golang this is safe, as Golang performs escape analysis, and any object taken references from and escapes are actually allocated to heap with GC. But in Rust it is not.

@JakkuSakura
Copy link
Author

Ok, I read the code of the Receiver side. The Sender will not leave the function when the Receiver reads out the value. So data will remain valid then

@fereidani
Copy link
Owner

Yes, it's true, so it's not UB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants