Skip to content

Commit ef43a9b

Browse files
committed
Use &[u8] instead of Vec<u8>
1 parent de515da commit ef43a9b

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

src/shims/unix/fd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl FileDescription for io::Stdin {
143143
helpers::isolation_abort_error("`read` from stdin")?;
144144
}
145145
let result = Read::read(&mut { self }, &mut bytes);
146-
ecx.return_read_bytes_and_count(ptr, bytes, result, dest)
146+
ecx.return_read_bytes_and_count(ptr, &bytes, result, dest)
147147
}
148148

149149
fn is_tty(&self, communicate_allowed: bool) -> bool {
@@ -646,7 +646,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
646646
fn return_read_bytes_and_count(
647647
&mut self,
648648
buf: Pointer,
649-
bytes: Vec<u8>,
649+
bytes: &[u8],
650650
result: io::Result<usize>,
651651
dest: &MPlaceTy<'tcx>,
652652
) -> InterpResult<'tcx> {

src/shims/unix/fs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl FileDescription for FileHandle {
4242
assert!(communicate_allowed, "isolation should have prevented even opening a file");
4343
let mut bytes = vec![0; usize::try_from(len).unwrap()];
4444
let result = (&mut &self.file).read(&mut bytes);
45-
ecx.return_read_bytes_and_count(ptr, bytes.to_vec(), result, dest)
45+
ecx.return_read_bytes_and_count(ptr, &bytes, result, dest)
4646
}
4747

4848
fn write<'tcx>(
@@ -83,7 +83,7 @@ impl FileDescription for FileHandle {
8383
res
8484
};
8585
let result = f();
86-
ecx.return_read_bytes_and_count(ptr, bytes.to_vec(), result, dest)
86+
ecx.return_read_bytes_and_count(ptr, &bytes, result, dest)
8787
}
8888

8989
fn pwrite<'tcx>(

src/shims/unix/unnamed_socket.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl FileDescription for AnonSocket {
137137
// Always succeed on read size 0.
138138
if request_byte_size == 0 {
139139
let result = Ok(0);
140-
return ecx.return_read_bytes_and_count(ptr, bytes.to_vec(), result, dest);
140+
return ecx.return_read_bytes_and_count(ptr, &bytes, result, dest);
141141
}
142142

143143
let Some(readbuf) = &self.readbuf else {
@@ -151,7 +151,7 @@ impl FileDescription for AnonSocket {
151151
// Socketpair with no peer and empty buffer.
152152
// 0 bytes successfully read indicates end-of-file.
153153
let result = Ok(0);
154-
return ecx.return_read_bytes_and_count(ptr, bytes.to_vec(), result, dest);
154+
return ecx.return_read_bytes_and_count(ptr, &bytes, result, dest);
155155
} else {
156156
if self.is_nonblock {
157157
// Non-blocking socketpair with writer and empty buffer.
@@ -160,7 +160,7 @@ impl FileDescription for AnonSocket {
160160
// POSIX.1-2001 allows either error to be returned for this case.
161161
// Since there is no ErrorKind for EAGAIN, WouldBlock is used.
162162
let result = Err(Error::from(ErrorKind::WouldBlock));
163-
return ecx.return_read_bytes_and_count(ptr, bytes.to_vec(), result, dest);
163+
return ecx.return_read_bytes_and_count(ptr, &bytes, result, dest);
164164
} else {
165165
// Blocking socketpair with writer and empty buffer.
166166
// FIXME: blocking is currently not supported
@@ -193,7 +193,7 @@ impl FileDescription for AnonSocket {
193193
}
194194

195195
let result = Ok(actual_read_size);
196-
ecx.return_read_bytes_and_count(ptr, bytes.to_vec(), result, dest)
196+
ecx.return_read_bytes_and_count(ptr, &bytes, result, dest)
197197
}
198198

199199
fn write<'tcx>(

0 commit comments

Comments
 (0)