@@ -55,34 +55,32 @@ mod t {
55
55
// https://github.com/rust-lang/libc/issues/1239
56
56
#[ cfg( not( target_arch = "sparc64" ) ) ]
57
57
#[ test]
58
- // FIXME: This triggers alignment checks for pointer dereferences:
59
- // https://github.com/rust-lang/libc/issues/3181
60
- #[ ignore]
61
58
fn test_cmsg_nxthdr ( ) {
62
59
use std:: ptr;
60
+ // Helps to align the buffer on the stack.
61
+ #[ repr( align( 8 ) ) ]
62
+ struct Align8 < T > ( T ) ;
63
63
64
- let mut buffer = [ 0u8 ; 256 ] ;
64
+ const CAPACITY : usize = 512 ;
65
+ let mut buffer = Align8 ( [ 0_u8 ; CAPACITY ] ) ;
65
66
let mut mhdr: msghdr = unsafe { mem:: zeroed ( ) } ;
66
- let pmhdr = & mhdr as * const msghdr ;
67
67
for start_ofs in 0 ..64 {
68
- let pcmsghdr = & mut buffer[ start_ofs ] as * mut u8 as * mut cmsghdr ;
68
+ let pcmsghdr = buffer. 0 . as_mut_ptr ( ) . cast :: < cmsghdr > ( ) ;
69
69
mhdr. msg_control = pcmsghdr as * mut c_void ;
70
70
mhdr. msg_controllen = ( 160 - start_ofs) as _ ;
71
71
for cmsg_len in 0 ..64 {
72
72
for next_cmsg_len in 0 ..32 {
73
- for i in buffer[ start_ofs..] . iter_mut ( ) {
74
- * i = 0 ;
75
- }
76
73
unsafe {
74
+ pcmsghdr. cast :: < u8 > ( ) . write_bytes ( 0 , CAPACITY ) ;
77
75
( * pcmsghdr) . cmsg_len = cmsg_len;
78
- let libc_next = libc:: CMSG_NXTHDR ( pmhdr , pcmsghdr) ;
79
- let next = cmsg_nxthdr ( pmhdr , pcmsghdr) ;
76
+ let libc_next = libc:: CMSG_NXTHDR ( & mhdr , pcmsghdr) ;
77
+ let next = cmsg_nxthdr ( & mhdr , pcmsghdr) ;
80
78
assert_eq ! ( libc_next, next) ;
81
79
82
80
if libc_next != ptr:: null_mut ( ) {
83
81
( * libc_next) . cmsg_len = next_cmsg_len;
84
- let libc_next = libc:: CMSG_NXTHDR ( pmhdr , pcmsghdr) ;
85
- let next = cmsg_nxthdr ( pmhdr , pcmsghdr) ;
82
+ let libc_next = libc:: CMSG_NXTHDR ( & mhdr , pcmsghdr) ;
83
+ let next = cmsg_nxthdr ( & mhdr , pcmsghdr) ;
86
84
assert_eq ! ( libc_next, next) ;
87
85
}
88
86
}
0 commit comments