about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorPietro Albini <pietro@pietroalbini.org>2018-11-25 17:05:11 +0100
committerGitHub <noreply@github.com>2018-11-25 17:05:11 +0100
commitbaf45d6d9001baeb7dfded52a6695266a8d631d0 (patch)
treedb635d2a947aa0b5ea1b00bff8fb57d1a882ff95 /src
parentd21d510dde71523f4ce52805e50582cd2f0676fd (diff)
parent2472e832503995a024a6fbf533b504a0d0bf9e9c (diff)
downloadrust-baf45d6d9001baeb7dfded52a6695266a8d631d0.tar.gz
rust-baf45d6d9001baeb7dfded52a6695266a8d631d0.zip
Rollup merge of #56210 - RalfJung:c_str, r=oli-obk
read_c_str should call the AllocationExtra hooks

I just hope we do not have other methods that bypass `get_bytes`/`get_bytes_mut`... (looking over the file, I could not find any)

r? @oli-obk
Diffstat (limited to 'src')
-rw-r--r--src/librustc/mir/interpret/allocation.rs17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/librustc/mir/interpret/allocation.rs b/src/librustc/mir/interpret/allocation.rs
index c612d6ad1bb..ab63e882c4a 100644
--- a/src/librustc/mir/interpret/allocation.rs
+++ b/src/librustc/mir/interpret/allocation.rs
@@ -172,10 +172,11 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
         let offset = ptr.offset.bytes() as usize;
         match self.bytes[offset..].iter().position(|&c| c == 0) {
             Some(size) => {
-                let p1 = Size::from_bytes((size + 1) as u64);
-                self.check_relocations(cx, ptr, p1)?;
-                self.check_defined(ptr, p1)?;
-                Ok(&self.bytes[offset..offset + size])
+                let size_with_null = Size::from_bytes((size + 1) as u64);
+                // Go through `get_bytes` for checks and AllocationExtra hooks.
+                // We read the null, so we include it in the request, but we want it removed
+                // from the result!
+                Ok(&self.get_bytes(cx, ptr, size_with_null)?[..size])
             }
             None => err!(UnterminatedCString(ptr.erase_tag())),
         }
@@ -315,11 +316,9 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
             },
         };
 
-        {
-            let endian = cx.data_layout().endian;
-            let dst = self.get_bytes_mut(cx, ptr, type_size)?;
-            write_target_uint(endian, dst, bytes).unwrap();
-        }
+        let endian = cx.data_layout().endian;
+        let dst = self.get_bytes_mut(cx, ptr, type_size)?;
+        write_target_uint(endian, dst, bytes).unwrap();
 
         // See if we have to also write a relocation
         match val {