2 ms·
No, you are wrong. First, mapping that page doesn't cause all null pointer dereferences to segfault. And second, the language doesn't require a segfault. In f
by jjnoakes 12y ago
No, you are wrong.
First, mapping that page doesn't cause all null pointer dereferences to segfault.
And second, the language doesn't require a segfault. In fact, it explicitly permits the implementation to do whatever it likes.
That is the difference between safe and unsafe. It is in the language definition.
- dbaupp 12y ago"the language"... which one? AIUI, Go doesn't state that null dereferences are undefined behaviour, but rather that they are guaranteed to panic.
- richo 12y ago"The language" ? C doesn't define behaviour of a null deref, but most compilers map a -rwx page there to ensure that attempts to deref fault. In what circumstance do they not?
- dbaupp 12y agoThe compilers don't map pages there, the operating system does. The problem is the compiler will optimise assuming that a null deref never happens, so you can have source that looks like it should crash due to a null deref, but the compiler has "misoptimised" it to have very different behaviour. http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html http://blog.llvm.org/2011/05/what-every-c-programmer-should-...