2 ms·
This here exactly. Dereferencing null. Oh maybe the compiler can figure out a pointer is null and try and ratfuck you in the name of some obscure 'optimization'
by Gibbon1 6y ago
This here exactly. Dereferencing null. Oh maybe the compiler can figure out a pointer is null and try and ratfuck you in the name of some obscure 'optimization'. But when it can't what happens depends on the machine.
Big iron machines with mmu's will invariably throw a seg fault. Some MCU's without an MMU will either seg fault because no physical memory exists[1] or return garbage. Some machines you get interesting things like the initial stack pointer. Or a memory mapped register.
[1] Trapping seg faults and logging address of the offender takes most of the pain away.
- com2kid 6y agoThis is why MCUs are better. 0 is where memory starts, there is perfectly valid data at address 0. Pointers aren't the problem, NULL coloring pointers and the compiler tracking that, that is the problem. In a sane world '0' would be a perfectly valid address just like any other.