Skip to content

[test] Missing Test Size for SockAddr #1280

Closed

Description

Description

In the test_size_demi_sgarray_t() unit test function, we are relying on the compiler to compute the size of SockAddr.

This is against the idea of this test: ensuring that the structure matches a size that we want. This property is important to avoid UB when crossing language boundaries.

Code Snippets

fn test_size_demi_sgarray_t() -> Result<(), anyhow::Error> {
// Size of a void pointer.
const SGA_BUF_SIZE: usize = 8;
// Size of a u32.
const SGA_NUMSEGS_SIZE: usize = 4;
// Size of an array of demi_sgaseg_t structures.
const SGA_SEGS_SIZE: usize = mem::size_of::<demi_sgaseg_t>() * DEMI_SGARRAY_MAXLEN;
// Size of a SockAddr structure.
const SGA_ADDR_SIZE: usize = mem::size_of::<SockAddr>();
// Size of a demi_sgarray_t structure.
crate::ensure_eq!(
mem::size_of::<demi_sgarray_t>(),
SGA_BUF_SIZE + SGA_NUMSEGS_SIZE + SGA_SEGS_SIZE + SGA_ADDR_SIZE
);
Ok(())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

bugSomething Isn't WorkingconfirmedIssue Affects Multiple People

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions