Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concerning use of empty enums for opaque types #358

Open
FeldrinH opened this issue Jun 6, 2024 · 1 comment
Open

Concerning use of empty enums for opaque types #358

FeldrinH opened this issue Jun 6, 2024 · 1 comment

Comments

@FeldrinH
Copy link

FeldrinH commented Jun 6, 2024

pcap_t and pcap_dumper_t seem to be represented by empty enums on the Rust side. According to the Rustonomicon this is a bad idea.

From https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs:

Notice that it is a really bad idea to use an empty enum as FFI type. The compiler relies on empty enums being uninhabited, so handling values of type &Empty is a huge footgun and can lead to buggy program behavior (by triggering undefined behavior).

@Stargateur
Copy link
Contributor

And according to C standard having an empty array is completely impossible yet the Rustonomicon put a empty array in a struct with repr(C).

Anyway, I have nothing against use a struct instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants