Skip to content

Commit 6a98c64

Browse files
authored
final tweaks
1 parent b0a4633 commit 6a98c64

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/intptrcast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ impl<'mir, 'tcx> GlobalState {
108108

109109
// Remember next base address. Leave a gap of at least 1 to avoid two zero-sized allocations
110110
// having the same base address, and to avoid ambiguous provenance for the address between two
111-
// allocations.
112-
let bytes = size.bytes().checked_add(1).unwrap();
113-
global_state.next_base_addr = base_addr.checked_add(bytes).unwrap();
111+
// allocations (also see https://github.com/rust-lang/unsafe-code-guidelines/issues/313).
112+
let size_plus_1 = size.bytes().checked_add(1).unwrap();
113+
global_state.next_base_addr = base_addr.checked_add(size_plus_1).unwrap();
114114
// Given that `next_base_addr` increases in each allocation, pushing the
115115
// corresponding tuple keeps `int_to_ptr_map` sorted
116116
global_state.int_to_ptr_map.push((base_addr, alloc_id));

tests/run-pass/adjacent-allocs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ fn main() {
1616

1717
let iptr = ptr as usize;
1818
let zst = (iptr + 8) as *const ();
19+
// This is a ZST ptr just at the end of `n`, so it should be valid to deref.
1920
unsafe { *zst }
2021
}
2122
}

0 commit comments

Comments
 (0)