|
|
Log in / Subscribe / Register

Why not?

Why not?

Posted Nov 21, 2025 14:17 UTC (Fri) by gmatht (guest, #58961)
In reply to: MISRA C is not provably safe. by tialaramex
Parent article: Rust in Android: move fast and fix things (Google Security Blog)

The major innovation in Rust is the borrow checker. This does not accept all valid programs but (should) only accept valid programs.

Writing a general borrow checker for C is hard because C lacks the lifetime annotations and valid standards compliant C code may not conform to the borrow checkers expectations.

However MISRA-C is much more pedantic than the Rust borrow-checker. Since dynamic allocations are banned, unless all lifetimes are static, the program is not valid MISRA-C. And if all lifetimes are static, lifetime annotations are redundant, and lifetime checks are redundant.

There are lots of edge cases to consider, for example, if race conditions could result in memory unsafety. However, it seems that if a compiler is allowed to reject non-MISRA-C this would make it vastly easier to only accept provably safe programs.


to post comments

Why not?

Posted Nov 21, 2025 15:21 UTC (Fri) by excors (subscriber, #95769) [Link]

> However MISRA-C is much more pedantic than the Rust borrow-checker. Since dynamic allocations are banned, unless all lifetimes are static, the program is not valid MISRA-C. And if all lifetimes are static, lifetime annotations are redundant, and lifetime checks are redundant.

MISRA C still allows automatic storage duration (i.e. stack variables), so not all lifetimes are static, and you can get bugs when a stack pointer escapes the function's scope.

MISRA C has the rule "The address of an object with automatic or thread-local storage shall not be copied to another object that persists after the first object has ceased to exist", but that's an explicitly undecidable rule, so it's basically saying "your program must not be buggy".

Some static checkers apparently detect simple violations of that rule (e.g. assigning the address to a global variable or returning it from the function that allocated it: https://www.mathworks.com/help/bugfinder/ref/misrac2023ru...), but I don't believe it's possible to detect all violations in otherwise-compliant code without rejecting plenty of reasonable and fully-compliant code.


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