I’m rewriting a large chunk of my FFI guide and at the end I’m including a “fun” chapter on all the ways you can break stuff when interoperating between languages.
The exercise will be as follows, each problem will contain the source code for a small program which deliberately does something horribly wrong, incorrect, or dangerous (memory safety, data races, undefined behaviour, that sort of thing). It’s then your job to figure out what the issue is and why it could end up hurting your application.
I’m looking for as many examples of undefined behaviour, memory issues, and other common mistakes as possible so we can pose them as problems and discuss what is happening and why it may end unpleasantly. If you can think of any good examples of this, please post them here
As an example, one of my “problems” is where a Rust function called by C++ panics. Then in the solutions we’ll go through saying why panicking across the FFI boundary is UB and ways you can prevent it.