Skip to content

Commit 6192971

Browse files
committed
Auto merge of #3183 - ChrisDenton:align-stack-buffer, r=<try>
Use aligned `cmsghdr` structs `test_cmsg_nxthdr` Fixes #3181. I could find no reason for using unaligned structs in this test.
2 parents 7adf246 + 4d5f5af commit 6192971

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

libc-test/test/cmsg.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ mod t {
1111

1212
extern "C" {
1313
pub fn cmsg_firsthdr(msgh: *const msghdr) -> *mut cmsghdr;
14-
// see below
15-
#[cfg(not(target_arch = "sparc64"))]
1614
pub fn cmsg_nxthdr(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr;
1715
pub fn cmsg_space(length: c_uint) -> usize;
1816
pub fn cmsg_len(length: c_uint) -> usize;
@@ -51,21 +49,16 @@ mod t {
5149
}
5250
}
5351

54-
// Skip on sparc64
55-
// https://github.com/rust-lang/libc/issues/1239
56-
#[cfg(not(target_arch = "sparc64"))]
5752
#[test]
58-
// FIXME: This triggers alignment checks for pointer dereferences:
59-
// https://github.com/rust-lang/libc/issues/3181
60-
#[ignore]
6153
fn test_cmsg_nxthdr() {
6254
use std::ptr;
6355

64-
let mut buffer = [0u8; 256];
56+
const CAPACITY: usize = 64 + 196 / mem::size_of::<usize>();
57+
let mut buffer = [0_usize; CAPACITY];
6558
let mut mhdr: msghdr = unsafe { mem::zeroed() };
6659
let pmhdr = &mhdr as *const msghdr;
6760
for start_ofs in 0..64 {
68-
let pcmsghdr = &mut buffer[start_ofs] as *mut u8 as *mut cmsghdr;
61+
let pcmsghdr = &mut buffer[start_ofs] as *mut usize as *mut cmsghdr;
6962
mhdr.msg_control = pcmsghdr as *mut c_void;
7063
mhdr.msg_controllen = (160 - start_ofs) as _;
7164
for cmsg_len in 0..64 {

0 commit comments

Comments
 (0)