File tree 2 files changed +4
-3
lines changed
2 files changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -108,9 +108,9 @@ impl<'mir, 'tcx> GlobalState {
108
108
109
109
// Remember next base address. Leave a gap of at least 1 to avoid two zero-sized allocations
110
110
// 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 ( ) ;
114
114
// Given that `next_base_addr` increases in each allocation, pushing the
115
115
// corresponding tuple keeps `int_to_ptr_map` sorted
116
116
global_state. int_to_ptr_map . push ( ( base_addr, alloc_id) ) ;
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ fn main() {
16
16
17
17
let iptr = ptr as usize ;
18
18
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.
19
20
unsafe { * zst }
20
21
}
21
22
}
You can’t perform that action at this time.
0 commit comments