-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add valid examples to std::ptr::{read,write}_unaligned
#62357
Labels
A-docs
Area: documentation for any part of the project, including the compiler, standard library, and tools
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
E-easy
Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Comments
Centril
added
A-docs
Area: documentation for any part of the project, including the compiler, standard library, and tools
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
labels
Jul 4, 2019
Slices are one context in which one could conceivably create an unaligned raw pointer: fn read_usize(x: &[u8]) -> usize {
assert!(x.len() >= mem::size_of::<usize>());
let ptr = x.as_ptr() as *const usize;
unsafe { ptr.read_unaligned() }
} Thanks to @Shnatsel on Zulip. The fix for this bug thus is to add an example like this, and a similar one for writes, to the docs for |
RalfJung
added
the
E-easy
Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
label
Jul 4, 2019
Hello! I would like to work on this one :) |
@rustbot claim |
Centril
added a commit
to Centril/rust
that referenced
this issue
Jul 10, 2019
…unaligned, r=rkruppe rust-lang#62357: doc(ptr): add example for {read,write}_unaligned related to rust-lang#62357 > With rust-lang#62323 the only example (that had UB and was thus invalid) in std::ptr::read_unaligned and std::ptr::write_unaligned is removed. > We should add a valid example of using the aforementioned functions. Signed-off-by: Freyskeyd <[email protected]>
bors
added a commit
that referenced
this issue
Jul 10, 2019
Rollup of 5 pull requests Successful merges: - #62275 (rustc_mir: treat DropAndReplace as Drop + Assign in qualify_consts.) - #62465 (Sometimes generate storage statements for temporaries with type `!`) - #62481 (Use `fold` in `Iterator::last` default implementation) - #62493 (#62357: doc(ptr): add example for {read,write}_unaligned) - #62532 (Some more cleanups to syntax::print) Failed merges: r? @ghost
bors
added a commit
that referenced
this issue
Jul 10, 2019
Rollup of 5 pull requests Successful merges: - #62275 (rustc_mir: treat DropAndReplace as Drop + Assign in qualify_consts.) - #62465 (Sometimes generate storage statements for temporaries with type `!`) - #62481 (Use `fold` in `Iterator::last` default implementation) - #62493 (#62357: doc(ptr): add example for {read,write}_unaligned) - #62532 (Some more cleanups to syntax::print) Failed merges: r? @ghost
Fixed by #62493. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-docs
Area: documentation for any part of the project, including the compiler, standard library, and tools
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
E-easy
Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
With #62323 the only example (that had UB and was thus invalid) in
std::ptr::read_unaligned
andstd::ptr::write_unaligned
is removed.We should add a valid example of using the aforementioned functions.
cc @rust-lang/wg-unsafe-code-guidelines
This issue has been assigned to @Freyskeyd via this comment.
The text was updated successfully, but these errors were encountered: