about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2023-10-14 11:52:49 +0200
committerRalf Jung <post@ralfj.de>2023-10-19 22:15:59 +0200
commitf3863294a8e3d0403e1b602f7f235038bc18a9c1 (patch)
treebb67a70e48bc549f33952215e4dab6005bb816c4
parent5d62040fb6702cccb1916e69d5fc8f3d61100db4 (diff)
downloadrust-f3863294a8e3d0403e1b602f7f235038bc18a9c1.tar.gz
rust-f3863294a8e3d0403e1b602f7f235038bc18a9c1.zip
intptrcast: only find strictly in-bounds pointers when we are not hitting the base address
-rw-r--r--src/tools/miri/src/intptrcast.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/tools/miri/src/intptrcast.rs b/src/tools/miri/src/intptrcast.rs
index 0bdea157633..d0ebaba4904 100644
--- a/src/tools/miri/src/intptrcast.rs
+++ b/src/tools/miri/src/intptrcast.rs
@@ -82,9 +82,12 @@ impl<'mir, 'tcx> GlobalStateInner {
                 let (glb, alloc_id) = global_state.int_to_ptr_map[pos - 1];
                 // This never overflows because `addr >= glb`
                 let offset = addr - glb;
-                // If the offset exceeds the size of the allocation, don't use this `alloc_id`.
+                // We require this to be strict in-bounds of the allocation. This arm is only
+                // entered for addresses that are not the base address, so even zero-sized
+                // allocations will get recognized at their base address -- but all other
+                // allocations will *not* be recognized at their "end" address.
                 let size = ecx.get_alloc_info(alloc_id).0;
-                if offset <= size.bytes() { Some(alloc_id) } else { None }
+                if offset < size.bytes() { Some(alloc_id) } else { None }
             }
         }?;