Skip to content

Commit 05f4a57

Browse files
committed
forward read_c_str method from Memory to Alloc
1 parent 0af8e87 commit 05f4a57

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Diff for: src/librustc_mir/interpret/memory.rs

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

678678
/// Reading and writing.
679679
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
680+
/// Reads the given number of bytes from memory. Returns them as a slice.
681+
///
680682
/// Performs appropriate bounds checks.
681683
pub fn read_bytes(
682684
&self,
@@ -690,6 +692,14 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
690692
self.get(ptr.alloc_id)?.get_bytes(self, ptr, size)
691693
}
692694

695+
/// Reads a 0-terminated sequence of bytes from memory. Returns them as a slice.
696+
///
697+
/// Performs appropriate bounds checks.
698+
pub fn read_c_str(&self, ptr: Scalar<M::PointerTag>) -> InterpResult<'tcx, &[u8]> {
699+
let ptr = self.force_ptr(ptr)?; // We need to read at least 1 byte, so we *need* a ptr.
700+
self.get(ptr.alloc_id)?.read_c_str(self, ptr)
701+
}
702+
693703
/// Performs appropriate bounds checks.
694704
pub fn copy(
695705
&mut self,

0 commit comments

Comments
 (0)