Skip to content

Commit baf45d6

Browse files
authored
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
2 parents d21d510 + 2472e83 commit baf45d6

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/librustc/mir/interpret/allocation.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -172,10 +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 p1 = Size::from_bytes((size + 1) as u64);
176-
self.check_relocations(cx, ptr, p1)?;
177-
self.check_defined(ptr, p1)?;
178-
Ok(&self.bytes[offset..offset + 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 request, but we want it removed
178+
// from the result!
179+
Ok(&self.get_bytes(cx, ptr, size_with_null)?[..size])
179180
}
180181
None => err!(UnterminatedCString(ptr.erase_tag())),
181182
}
@@ -315,11 +316,9 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
315316
},
316317
};
317318

318-
{
319-
let endian = cx.data_layout().endian;
320-
let dst = self.get_bytes_mut(cx, ptr, type_size)?;
321-
write_target_uint(endian, dst, bytes).unwrap();
322-
}
319+
let endian = cx.data_layout().endian;
320+
let dst = self.get_bytes_mut(cx, ptr, type_size)?;
321+
write_target_uint(endian, dst, bytes).unwrap();
323322

324323
// See if we have to also write a relocation
325324
match val {

0 commit comments

Comments
 (0)