From af54eb2916b9f5707c7bfa577f5db29918870ce2 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 25 Nov 2018 10:56:10 +0100 Subject: [PATCH 1/4] read_c_str should call the AllocationExtra hooks --- src/librustc/mir/interpret/allocation.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/librustc/mir/interpret/allocation.rs b/src/librustc/mir/interpret/allocation.rs index c612d6ad1bb..406d41d3436 100644 --- a/src/librustc/mir/interpret/allocation.rs +++ b/src/librustc/mir/interpret/allocation.rs @@ -172,10 +172,9 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra> Allocation { 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 = Size::from_bytes((size + 1) as u64); + // Go through `get_bytes` for checks and AllocationExtra hooks + self.get_bytes(cx, ptr, size) } None => err!(UnterminatedCString(ptr.erase_tag())), } From 0fac350f9982b78ef5c74ac7db98933262d361b5 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 25 Nov 2018 11:23:21 +0100 Subject: [PATCH 2/4] yay for NLL --- src/librustc/mir/interpret/allocation.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/librustc/mir/interpret/allocation.rs b/src/librustc/mir/interpret/allocation.rs index 406d41d3436..3ff0e9f177d 100644 --- a/src/librustc/mir/interpret/allocation.rs +++ b/src/librustc/mir/interpret/allocation.rs @@ -314,11 +314,9 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra> Allocation { }, }; - { - 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 { From a6ea01f2396a55c5245b93b8f9c6edd3c5a0e204 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 25 Nov 2018 12:07:20 +0100 Subject: [PATCH 3/4] fix length of slice returned from read_c_str --- src/librustc/mir/interpret/allocation.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/librustc/mir/interpret/allocation.rs b/src/librustc/mir/interpret/allocation.rs index 3ff0e9f177d..0ecec753398 100644 --- a/src/librustc/mir/interpret/allocation.rs +++ b/src/librustc/mir/interpret/allocation.rs @@ -172,9 +172,11 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra> Allocation { let offset = ptr.offset.bytes() as usize; match self.bytes[offset..].iter().position(|&c| c == 0) { Some(size) => { - let size = Size::from_bytes((size + 1) as u64); - // Go through `get_bytes` for checks and AllocationExtra hooks - self.get_bytes(cx, ptr, 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 requestm, but we want it removed + // from the result! + Ok(&self.get_bytes(cx, ptr, size_with_null)?[..size]) } None => err!(UnterminatedCString(ptr.erase_tag())), } From 2472e832503995a024a6fbf533b504a0d0bf9e9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20S=CC=B6c=CC=B6h=CC=B6n=CC=B6e=CC=B6i=CC=B6d=CC=B6?= =?UTF-8?q?e=CC=B6r=20Scherer?= Date: Sun, 25 Nov 2018 14:21:34 +0100 Subject: [PATCH 4/4] Typo Co-Authored-By: RalfJung --- src/librustc/mir/interpret/allocation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/mir/interpret/allocation.rs b/src/librustc/mir/interpret/allocation.rs index 0ecec753398..ab63e882c4a 100644 --- a/src/librustc/mir/interpret/allocation.rs +++ b/src/librustc/mir/interpret/allocation.rs @@ -174,7 +174,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra> Allocation { Some(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 requestm, but we want it removed + // 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]) }