Skip to content

Commit 6674d78

Browse files
chrysnfw-immunant
authored andcommitted
Add tests for packed unions
1 parent 6a5c3a9 commit 6674d78

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

tests/unions/src/test_unions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ extern "C" {
99
fn entry(_: c_uint, _: *mut c_int);
1010
}
1111

12-
const BUFFER_SIZE: usize = 18;
12+
const BUFFER_SIZE: usize = 19;
1313

1414
pub fn test_buffer() {
1515
let mut buffer = [0; BUFFER_SIZE];
1616
let mut rust_buffer = [0; BUFFER_SIZE];
17-
let expected_buffer = [12, 12, 0, 1, 2, 3, 4, 0, 5, 6, 7, 8, 0, 8, 9, 10, 12, 17];
17+
let expected_buffer = [12, 12, 0, 5, 1, 2, 3, 4, 0, 5, 6, 7, 8, 0, 8, 9, 10, 12, 18];
1818

1919
unsafe {
2020
entry(BUFFER_SIZE as u32, buffer.as_mut_ptr());

tests/unions/src/unions.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ union union_with_anon_struct {
1717
};
1818
};
1919

20+
union __attribute__((packed)) packed_union {
21+
int as_int;
22+
char as_chars[5];
23+
};
24+
2025
void entry(const unsigned int buffer_size, int buffer[const])
2126
{
2227
int i = 0;
@@ -35,6 +40,7 @@ void entry(const unsigned int buffer_size, int buffer[const])
3540
buffer[i++] = sizeof(union my_union);
3641
buffer[i++] = sizeof(union my_union_flipped);
3742
buffer[i++] = sizeof(union empty_union);
43+
buffer[i++] = sizeof(union packed_union);
3844
buffer[i++] = u1.as_int;
3945
buffer[i++] = u2.as_int;
4046
buffer[i++] = u3.as_chars[0];

0 commit comments

Comments
 (0)