Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Add valid examples to std::ptr::{read,write}_unaligned #62357

Closed

Description

@Centril

With #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.

cc @rust-lang/wg-unsafe-code-guidelines

This issue has been assigned to @Freyskeyd via this comment.

Activity

  1. added
    A-docs
    C-enhancement
    on Jul 4, 2019
  2. RalfJung commented on Jul 4, 2019

    @RalfJung
    Member

    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 read_unaligned and write_unaligned. The docs should also explain why using just read or write is UB.

  3. added
    E-easy
    on Jul 4, 2019
  4. Freyskeyd commented on Jul 8, 2019

    @Freyskeyd
    Contributor

    Hello!

    I would like to work on this one :)

  5. Freyskeyd commented on Jul 8, 2019

    @Freyskeyd
    Contributor

    @rustbot claim

  6. self-assigned this
    on Jul 8, 2019
  7. added a commit that references this issue on Jul 10, 2019
  8. added 2 commits that reference this issue on Jul 10, 2019
  9. RalfJung commented on Jul 13, 2019

    @RalfJung
    Member

    Fixed by #62493.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-docsC-enhancementE-easy

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions