Memory-safe C code
Memory-safe C code
Posted Nov 16, 2025 17:46 UTC (Sun) by alx.manpages (subscriber, #145117)In reply to: Memory-safe C code by khim
Parent article: Rust in Android: move fast and fix things (Google Security Blog)
That's too simplistic. 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.
> Yes, but you can not teach compiler to reject code that triggers UB. That's fundamental difference.
I don't think I understand you. Here, I'm teaching the compiler to reject code that triggers UB, by passing -Werror=overflow:
alx@devuan:~/tmp$ cat ub.c
#include <limits.h>
int
main(void)
{
return INT_MAX + 1;
}
alx@devuan:~/tmp$ gcc -Werror=overflow ub.c
ub.c: In function ‘main’:
ub.c:6:24: error: integer overflow in expression of type ‘int’ results in ‘-2147483648’ [-Werror=overflow]
6 | return INT_MAX + 1;
| ^
cc1: some warnings being treated as errors
Please clarify if you mean something else.
> That's nice, but the problem with that approach is that, in the end of the road, you wouldn't have C, you would have some other language that can be compiled with C compiler.
What's C? K&R C? C89? C99? C11? C23? GNU C? There's no such thing as a pure C language. There are dialects; there have always been dialects. Some dialects are safer than others. Depending on the flags you pass to your compiler, you're creating your own dialect.
> If such thing would have been created 20 or even 10 years ago it would have been very interesting, but today… Rust already exist.
Improving existing C code to be safe is much easier than rewriting the world. Rust still doesn't exist, in a way.
