Skip to content

Commit 947d7cf

Browse files
authored
Rollup merge of rust-lang#62257 - RalfJung:miri-c-str, r=estebank
forward read_c_str method from Memory to Alloc This is more convenient to call when one starts with a `Scalar` (which is the common case). `read_c_str` is only used in Miri.
2 parents 182248a + 05f4a57 commit 947d7cf

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/librustc_mir/interpret/memory.rs

+10
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
728728

729729
/// Reading and writing.
730730
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
731+
/// Reads the given number of bytes from memory. Returns them as a slice.
732+
///
731733
/// Performs appropriate bounds checks.
732734
pub fn read_bytes(
733735
&self,
@@ -741,6 +743,14 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
741743
self.get(ptr.alloc_id)?.get_bytes(self, ptr, size)
742744
}
743745

746+
/// Reads a 0-terminated sequence of bytes from memory. Returns them as a slice.
747+
///
748+
/// Performs appropriate bounds checks.
749+
pub fn read_c_str(&self, ptr: Scalar<M::PointerTag>) -> InterpResult<'tcx, &[u8]> {
750+
let ptr = self.force_ptr(ptr)?; // We need to read at least 1 byte, so we *need* a ptr.
751+
self.get(ptr.alloc_id)?.read_c_str(self, ptr)
752+
}
753+
744754
/// Performs appropriate bounds checks.
745755
pub fn copy(
746756
&mut self,

0 commit comments

Comments
 (0)