Comment Start with gcc -fsanitize=address,undefined (Score 2) 44
What would your hardened version of C look like?
It'd look like a subset of C where the compiler emits a diagnostic for every undefined behavior that's practical to detect at compile time and inserts code to catch at runtime everything else the standard calls undefined. The first step toward this is what GCC already does for -Wall -Wextra -pedantic -fsanitize=address,undefined. The second step is that a pointer variable doesn't contain a raw address but instead a base address and index, and every dereference of an array member is bounds-checked against the size of the object it came from. This ends up making the language's strict aliasing rule even stricter, and a lot of pointer casts or union puns become undefined and therefore errors. After programmers become accustomed to stricter pointer provenance, a compiler maker can add a concept of ownership, with a borrow checker to detect use-after-free and the like.