3 ms·
It's fairly trivial to make one by dereferencing a pointer that just happens to be null based on user input, which the compiler can't check. There are several a
by Asooka 5y ago
It's fairly trivial to make one by dereferencing a pointer that just happens to be null based on user input, which the compiler can't check. There are several acceptable ways for the compiler to deal with it:
1. Require the programmer to prove to the compiler that the pointer is not null.
2. Insert null checks and abort the program if the pointer is null.
Both of those are deficient for me, because it's possible for some other bug to cause the memory holding the reference to be overwritten with 0, so I really favour:
3. Treat references as immutable pointers that can be null, but disallow creating them from pointers that are obviously constantly null.
Obviously currently all ways to obtain a null reference are UB, but at the same time the compiler happily produces a program that creates a null reference, but deletes the check for it. Which is the absolute worst possible way to do it. It's a needless optimisation that requires you to solve the halting problem to be safe.