|
|
Log in / Subscribe / Register

Memory-safe C code

Memory-safe C code

Posted Nov 15, 2025 23:08 UTC (Sat) by alx.manpages (subscriber, #145117)
In reply to: 1000x dubious by cyperpunks
Parent article: Rust in Android: move fast and fix things (Google Security Blog)

> while everything in C/C++ is unsafe by definition (as rust define it).

I don't think that's true. Not even with Rust's definition of memory safety.

It's possible to write memory safe APIs in C. It needs macro trickery, and combinations of modern language features.

The main difference with Rust is that you need to opt-in to safety, instead of opting out of it. Also, there's no 'unsafe' keyword that distinguishes such code from the surroundings. However, once your code base does extensive use of these APIs, you essentially get a safe program.

To be fair, the kind of safety you can guarantee in C is only spatial (bounds safety). Use-after-free bugs are still possible, even if less likely.


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.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds