Get the latest tech news
Generic Containers in C: Safe Division Using Maybe
ker, 2025-08-10 I discuss the implementation of type and bounds safe generic containers in C. Previously, I discussed a span type, bounds checking using arrays.
Now, there are tools and a complete industry that may be able to help with this, but instead let's first simply look at the assembly generated by GCC when using the signed overflow sanitizer in trapping mode with-O2 -fsanitize=signed-integer-overflow,integer-divide-by-zero -fsanitize-trap=undefined. Thus, one has to stress that this approach is very limited when trying to prove safety properties of legacy C programs in this way. Still, if you use VLAs and variably modified types instead of pointer arithmetic as discussed previously, you can even have your bounds checked; see for yourself example!
Or read this on Hacker News