Skip to content

Commit 491afc1

Browse files
committed
Auto merge of #3840 - RalfJung:pipe-to-array, r=RalfJung
fix calling pipe, pipe2, socketpair with a pointer-to-array Fixes #3839
2 parents cb55919 + 507fff5 commit 491afc1

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/shims/unix/unnamed_socket.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
339339
) -> InterpResult<'tcx, Scalar> {
340340
let this = self.eval_context_mut();
341341

342-
let pipefd = this.deref_pointer(pipefd)?;
342+
let pipefd = this.deref_pointer_as(pipefd, this.machine.layouts.i32)?;
343343
let flags = match flags {
344344
Some(flags) => this.read_scalar(flags)?.to_i32()?,
345345
None => 0,

tests/pass-dep/libc/libc-pipe.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ fn main() {
66
test_pipe();
77
test_pipe_threaded();
88
test_race();
9+
test_pipe_array();
910
}
1011

1112
fn test_pipe() {
@@ -97,3 +98,13 @@ fn test_race() {
9798
thread::yield_now();
9899
thread1.join().unwrap();
99100
}
101+
102+
fn test_pipe_array() {
103+
// Declare `pipe` to take an array rather than a `*mut i32`.
104+
extern "C" {
105+
fn pipe(pipefd: &mut [i32; 2]) -> i32;
106+
}
107+
108+
let mut fds: [i32; 2] = [0; 2];
109+
assert_eq!(unsafe { pipe(&mut fds) }, 0);
110+
}

0 commit comments

Comments
 (0)