Skip to content

Is a read() of the last byte in the address space allowed? #420

@RalfJung

Description

@RalfJung

Can it ever be fine to do a read() that covers the last byte of the address space? On their own there is nothing wrong with such reads, but allowing them means the following property is violated: if p.read() is fine, then p.add(1) is also well-defined.

@chorman0773 mentioned this property as desirable. I agree it is nice, though I don't see any concrete benefits. Is it desirable enough to introduce extra UB?

Note: it is already clear that having a &i32 cover the last byte of the address space violates the safety invariant. You can turn this into a 1-element array in-place and then iterate over it, which will do the equivalent of p.add(1). Therefore, an allocator that returns !0 for a 1-byte allocation request must already be considered invalid (or else every single user would have to check this before giving that raw pointer to some safe code as a reference).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions