5 ms·
Null is not really the most pertinent example in this context - at least you get a segfault. What is more important is that in C or C++ (even C++17), it is triv
by bjz_ 9y ago
Null is not really the most pertinent example in this context - at least you get a segfault. What is more important is that in C or C++ (even C++17), it is trivially easy to produce buffer overruns, use after frees, dangling pointers, invalidated iterators, data races etc. That is the unsafety that we are talking about here. Opt-in nullability via Option<T> is nice to have though.
- Ygg2 9y agoYeah, I went with familiarity/simplicity in that example. My point was similar C/C++ don't have a safe subset.
- adrianN 9y agoNot a safe subset anyone would want to use at least. You could just not use pointers in your code and you'd have memory safety.
- steveklabnik 9y agoYour code, or any of the code it calls; iterator invalidation, for example, wouldn't force you to use pointers directly, but can still cause memory unsafety.
- steveklabnik 9y ago> at least you get a segfault If the platform has an MMU, if you've properly set up your page table mappings, etc. We are talking about writing an OS here! Not to mention all the UB around null pointers that can cause miscompilation. Well, not technically miscompilation, but stuff like https://news.ycombinator.com/item?id=15324414 https://news.ycombinator.com/item?id=15324414
- ctz 9y ago> at least you get a segfault. If there were a list "falsehoods software engineers believe about memory safety" this should be there. https://cansecwest.com/slides07/Vector-Rewrite-Attack.pdf https://cansecwest.com/slides07/Vector-Rewrite-Attack.pdf