-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add valid examples to std::ptr::{read,write}_unaligned
#62357
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
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
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 |
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 <simon.paitrault@gmail.com>
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 + As# 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 + As# 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. |
# for free
to join this conversation on GitHub.
Already have an account?
# 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.
Uh oh!
There was an error while loading. Please reload this page.
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: