JohnTitor / ctest2

Automatic testing of FFI bindings for Rust
https://crates.io/crates/ctest2
Apache License 2.0
22 stars 20 forks source link

offset_of assumes structure can be zero-initialized #31

Closed joshtriplett closed 2 years ago

joshtriplett commented 2 years ago

The fix for #23 (in PR #24) calls mem::zeroed() to create a zero-initialized version of a structure. However, not all structures can be safely zero-initialized.

I discovered this when attempting to update libz-sys to ctest2 0.4.3 to get the fix for #23. One of the structures contained function pointers, which couldn't be zero-initialized, and this resulted in a pile of warnings as well as a runtime panic.

JohnTitor commented 2 years ago

Thanks for reporting, hmm, this is kinda difficult. So we have a similar issue that bindgen has, a simple fix would be reverting #24 and just allowing the lint but it's not ideal. Do you have any clue about this?

joshtriplett commented 2 years ago

I think there's a standard incantation for offset_of that doesn't use zeroed.

Zulip thread

JohnTitor commented 2 years ago

Thanks! Unfortunately we cannot use an external crate but the snippet there seems useful.