-
Notifications
You must be signed in to change notification settings - Fork 62
Description
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).