Skip to content

Commit 52fcf32

Browse files
usamoitgross35
authored andcommitted
checks termios size in the baud test
(backport <#4938>) (cherry picked from commit 44b709c)
1 parent 5971f2f commit 52fcf32

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

libc-test/tests/linux_gnu_baud.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,24 @@ fn baud() {
1313
assert!(ret >= 0);
1414
let terminal_fd = unsafe { open(buffer.as_ptr(), O_RDWR | O_NOCTTY) };
1515
assert!(terminal_fd >= 0);
16-
let mut tio: termios = unsafe { std::mem::zeroed() };
17-
let ret = unsafe { tcgetattr(terminal_fd, &mut tio) };
16+
#[repr(C)]
17+
struct Protector(termios, [u8; 512]);
18+
let mut tio: Protector = unsafe { Protector(std::mem::zeroed(), [0xcc; _]) };
19+
let ret = unsafe { tcgetattr(terminal_fd, &raw mut tio.0) };
1820
assert!(ret >= 0);
19-
assert_eq!(unsafe { cfgetispeed(&tio) }, B38400);
20-
assert_eq!(unsafe { cfgetospeed(&tio) }, B38400);
21-
let ret = unsafe { cfsetspeed(&mut tio, B1000000) };
21+
assert_eq!(tio.1, [0xcc; _]);
22+
assert_eq!(unsafe { cfgetispeed(&tio.0) }, B38400);
23+
assert_eq!(unsafe { cfgetospeed(&tio.0) }, B38400);
24+
let ret = unsafe { cfsetspeed(&mut tio.0, B1000000) };
2225
assert!(ret >= 0);
23-
assert_eq!(unsafe { cfgetispeed(&tio) }, B1000000);
24-
assert_eq!(unsafe { cfgetospeed(&tio) }, B1000000);
25-
let ret = unsafe { cfsetispeed(&mut tio, B9600) };
26+
assert_eq!(unsafe { cfgetispeed(&tio.0) }, B1000000);
27+
assert_eq!(unsafe { cfgetospeed(&tio.0) }, B1000000);
28+
let ret = unsafe { cfsetispeed(&mut tio.0, B9600) };
2629
assert!(ret >= 0);
27-
assert_eq!(unsafe { cfgetispeed(&tio) }, B9600);
28-
assert!(matches!(unsafe { cfgetospeed(&tio) }, B9600 | B1000000));
29-
let ret = unsafe { cfsetospeed(&mut tio, B19200) };
30+
assert_eq!(unsafe { cfgetispeed(&tio.0) }, B9600);
31+
assert!(matches!(unsafe { cfgetospeed(&tio.0) }, B9600 | B1000000));
32+
let ret = unsafe { cfsetospeed(&mut tio.0, B19200) };
3033
assert!(ret >= 0);
31-
assert!(matches!(unsafe { cfgetispeed(&tio) }, B9600 | B19200));
32-
assert_eq!(unsafe { cfgetospeed(&tio) }, B19200);
34+
assert!(matches!(unsafe { cfgetispeed(&tio.0) }, B9600 | B19200));
35+
assert_eq!(unsafe { cfgetospeed(&tio.0) }, B19200);
3336
}

0 commit comments

Comments
 (0)