about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2018-11-25 12:07:20 +0100
committerRalf Jung <post@ralfj.de>2018-11-25 12:07:20 +0100
commita6ea01f2396a55c5245b93b8f9c6edd3c5a0e204 (patch)
tree150c96da8f48c5931ef0973c1cf0b54609d864e0
parent0fac350f9982b78ef5c74ac7db98933262d361b5 (diff)
downloadrust-a6ea01f2396a55c5245b93b8f9c6edd3c5a0e204.tar.gz
rust-a6ea01f2396a55c5245b93b8f9c6edd3c5a0e204.zip
fix length of slice returned from read_c_str
-rw-r--r--src/librustc/mir/interpret/allocation.rs8
1 files 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<Tag>> Allocation<Tag, Extra> {
         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())),
         }