I feel the need to recycle an older comment of mine: https://news.ycombinator.com/item?id=50620032
Now let's see the list they gave:
• Buffer overflow -> Bounds checks.
• Null pointer dereference -> Basically safe outside of embedded.
• Use after free -> Hard (temporal safety).
• Use of uninitialized memory -> Compilers already warn us.
• Illegal free -> Hard (temporal safety).
In broad strokes. I don't think current C compilers catch all uninitialised memory use. Having a variant that enforces it however is pretty easy. Bounds checks are similar. Proving the absence of overflow at compile time is impossible in the general case without proof assistance, but we can always have an incomplete analysis that inserts runtime checks when it's not sure. Same thing for null pointer dereference, just add a checks on systems that don't guarantee a safe segfault.All those could easily be solved with a slightly modified C compiler already. Zig to name but one basically does it already. So we're left with the two hard ones: use after free, and illegal free. For those there are 3 well known solutions: garbage collection (a performance deal breaker in many cases), and borrow checking (a godsend or a pain in the butt, depending who you ask), and smart pointers (not quite safe in C++, but they do help a ton).
What's practically unheard of in the industry however are arenas. https://www.dgtlgrove.com/p/untangling-lifetimes-the-arena-a... Sure, most game devs know of this, and it does have serious traction in some circles (the Handmade community comes to mind). But never once have I seen it applied in my day job since I started 20 years ago. In fact, I have never seen anyone use anything other malloc()/free() or new/delete.
Which is a shame, because arenas have the potential to simplify memory management to the point where memory safety bugs (assuming we have proper bounds checks) drop near the bottom of our list of concerns. I mean, I'd be fairly surprised if in Zig or Odin projects that mostly use arenas, memory safety bugs still comprised 2/3rd of all high and critical vulnerabilities.
C compilers have had 50 years for introducing fat pointers as extension, they could even base the idea on Dennis Ritchie or Walter Bright proposals to WG 14, yet here we are.