- // Remember next base address. Leave a gap of at least 1 to avoid two zero-sized allocations
- // having the same base address, and to avoid ambiguous provenance for the address between two
- // allocations (also see https://github.com/rust-lang/unsafe-code-guidelines/issues/313).
- let size_plus_1 = size.bytes().checked_add(1).unwrap();
- global_state.next_base_addr = base_addr.checked_add(size_plus_1).unwrap();
+ // Remember next base address. If this allocation is zero-sized, leave a gap
+ // of at least 1 to avoid two allocations having the same base address.
+ // (The logic in `alloc_id_from_addr` assumes unique addresses, and function
+ // pointers to different functions need to be distinguishable!)
+ global_state.next_base_addr = base_addr.checked_add(max(size.bytes(), 1)).unwrap();