Skip to content

Commit a6ea01f

Browse files
committed
fix length of slice returned from read_c_str
1 parent 0fac350 commit a6ea01f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/librustc/mir/interpret/allocation.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,11 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
172172
let offset = ptr.offset.bytes() as usize;
173173
match self.bytes[offset..].iter().position(|&c| c == 0) {
174174
Some(size) => {
175-
let size = Size::from_bytes((size + 1) as u64);
176-
// Go through `get_bytes` for checks and AllocationExtra hooks
177-
self.get_bytes(cx, ptr, size)
175+
let size_with_null = Size::from_bytes((size + 1) as u64);
176+
// Go through `get_bytes` for checks and AllocationExtra hooks.
177+
// We read the null, so we include it in the requestm, but we want it removed
178+
// from the result!
179+
Ok(&self.get_bytes(cx, ptr, size_with_null)?[..size])
178180
}
179181
None => err!(UnterminatedCString(ptr.erase_tag())),
180182
}

0 commit comments

Comments
 (0)