Skip to content

Commit

Permalink
Fix bad vec usage
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Saveau <[email protected]>
  • Loading branch information
SUPERCILEX committed Aug 15, 2024
1 parent 966e296 commit 619d4fd
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions tests/net/unix_alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,13 @@ fn test_unix_msg_with_scm_rights() {
let mut pipe_end = None;

let mut buffer = vec![0; BUFFER_SIZE];
let mut cmsg_space = vec![MaybeUninit::uninit(); rustix::cmsg_space!(ScmRights(1))];
let mut cmsg_space = Vec::with_capacity(rustix::cmsg_space!(ScmRights(1)));

'exit: loop {
let data_socket = accept(&connection_socket).unwrap();
let mut sum = 0;
loop {
let mut cmsg_buffer = RecvAncillaryBuffer::new(&mut cmsg_space);
let mut cmsg_buffer = RecvAncillaryBuffer::new(cmsg_space.spare_capacity_mut());
let nread = recvmsg(
&data_socket,
&mut [IoSliceMut::new(&mut buffer)],
Expand Down Expand Up @@ -554,8 +554,8 @@ fn test_unix_msg_with_scm_rights() {
// Format the CMSG.
let we = [write_end.as_fd()];
let msg = SendAncillaryMessage::ScmRights(&we);
let mut space = vec![MaybeUninit::uninit(); msg.size()];
let mut cmsg_buffer = SendAncillaryBuffer::new(&mut space);
let mut space = Vec::with_capacity(msg.size());
let mut cmsg_buffer = SendAncillaryBuffer::new(space.spare_capacity_mut());
assert!(cmsg_buffer.push(msg));

connect_unix(&data_socket, &addr).unwrap();
Expand Down Expand Up @@ -619,8 +619,8 @@ fn test_unix_peercred() {
assert_eq!(ucred.gid, getgid());

let msg = SendAncillaryMessage::ScmCredentials(ucred);
let mut space = vec![MaybeUninit::uninit(); msg.size()];
let mut cmsg_buffer = SendAncillaryBuffer::new(&mut space);
let mut space = Vec::with_capacity(msg.size());
let mut cmsg_buffer = SendAncillaryBuffer::new(space.spare_capacity_mut());
assert!(cmsg_buffer.push(msg));

sendmsg(
Expand All @@ -631,8 +631,8 @@ fn test_unix_peercred() {
)
.unwrap();

let mut cmsg_space = vec![MaybeUninit::uninit(); rustix::cmsg_space!(ScmCredentials(1))];
let mut cmsg_buffer = RecvAncillaryBuffer::new(&mut cmsg_space);
let mut cmsg_space = Vec::with_capacity(rustix::cmsg_space!(ScmCredentials(1)));
let mut cmsg_buffer = RecvAncillaryBuffer::new(cmsg_space.spare_capacity_mut());

let mut buffer = vec![0; BUFFER_SIZE];
recvmsg(
Expand Down Expand Up @@ -684,13 +684,13 @@ fn test_unix_msg_with_combo() {

let mut buffer = vec![0; BUFFER_SIZE];
let mut cmsg_space =
vec![MaybeUninit::uninit(); rustix::cmsg_space!(ScmRights(1), ScmRights(2))];
Vec::with_capacity(rustix::cmsg_space!(ScmRights(1), ScmRights(2)));

'exit: loop {
let data_socket = accept(&connection_socket).unwrap();
let mut sum = 0;
loop {
let mut cmsg_buffer = RecvAncillaryBuffer::new(&mut cmsg_space);
let mut cmsg_buffer = RecvAncillaryBuffer::new(cmsg_space.spare_capacity_mut());
let nread = recvmsg(
&data_socket,
&mut [IoSliceMut::new(&mut buffer)],
Expand Down Expand Up @@ -806,9 +806,8 @@ fn test_unix_msg_with_combo() {

let data_socket = socket(AddressFamily::UNIX, SocketType::SEQPACKET, None).unwrap();

let mut space =
vec![MaybeUninit::uninit(); rustix::cmsg_space!(ScmRights(1), ScmRights(2))];
let mut cmsg_buffer = SendAncillaryBuffer::new(&mut space);
let mut space = Vec::with_capacity(rustix::cmsg_space!(ScmRights(1), ScmRights(2)));
let mut cmsg_buffer = SendAncillaryBuffer::new(space.spare_capacity_mut());

// Format a CMSG.
let we = [write_end.as_fd(), another_write_end.as_fd()];
Expand Down

0 comments on commit 619d4fd

Please sign in to comment.