3 ms·
The famous case in the linux kernel was caused by a code path which was technically dereferencing a null pointer (but not in practice generating a memory access
by rcxdude 2y ago
The famous case in the linux kernel was caused by a code path which was technically dereferencing a null pointer (but not in practice generating a memory access to the address it pointed to), then doing the check, then dereferencing it "for real". Something like:
int *m = &p->foo;
if(p) *p->bar;
What annoyed people was that while the first line technically dereferences p according to the C standard, all it does in practice is calculate an offset from p. But it was enough for the compiler to rmeove the if and execute the second line unconditionally, making the null pointer dereference "real" (as in the generated assembly would try to read some very low part of memory).
- Bjartr 2y agoAha! I've never had c/c++ as a daily driver, so I missed the significance of taking that reference. Thanks for the explanation!