Memory-safe C code
Memory-safe C code
Posted Nov 16, 2025 17:58 UTC (Sun) by khim (subscriber, #9252)In reply to: Memory-safe C code by alx.manpages
Parent article: Rust in Android: move fast and fix things (Google Security Blog)
> It's possible to prove that certain bugs can't happen, even if you can't prove others. And there's work for improving the cases where it can't.
This road leads to Zig, not to Rust.
> Here, I'm teaching the compiler to reject code that triggers UB, by passing -Werror=overflowYes, you are removing one, pretty minor UB. That's commendable, but not the point of safe languages. The main idea behind Java, C# and most other modern languages is that they can be explored “by poking”: if there are no UB and no “nasal daemons” then problems in your code can be investigated and, eventually, fixed. All critical bugs that are very hard to detect and fix live in the TCB (runtime for most language, in these 4% pieces of unsafe in Rust).
But if UB can exist anywhere in your code then everything in your code is TCB.
> Improving existing C code to be safe is much easier than rewriting the world. Rust still doesn't exist, in a way.I would believe it when I'll see it. Because I hear that mantra for about 20 years. Rust conceived and released in that time… C/C++ still have awful problems, even today.
I wish you luck, I'm just not sure if you would be able to do anything, the main problems of C are not technical, they are social: the fact that C have so many UBs is the minor (and fixable) issue, surprisingly enough, the main issue is that many C developers simply don't believe they need to avoid UB. At all.
Making UB visible in your code (like Rust did) is nice solution. Not sure you can add anything else while staying in C.
The LWN site is currently under high scraper load, so comment display has been suppressed for anonymous users. If you are a human, you may read the comments by clicking the button below:
Note: you can avoid this step in the future by logging into your LWN account.
