News for hackers. Stuff that matters.
Re:Dereferencing NULL Pointer, without a Seg Fault by eridius on Tuesday July 10, 2012 @09:52PM (#4227322)
Misleading headline and final sentence. The whole point of the article is that it's not dereferencing NULL. It's just passing NULL as a hidden parameter to a function, which in turn ignores that parameter.

I also found it rather odd that the author spent so much time defining what a pointer is and what dereferencing is, when the article won't be of any interest whatsoever to someone who doesn't already know these things.

And lastly, when I saw the headline about dereferencing NULL, I expected it to be a discussion regarding the circumstances in which you can actually map address 0 to valid memory (and therefore dereference NULL without crashing), and the consequences thereof.

Re:Dereferencing NULL Pointer, without a Seg Fault by sharkbot on Tuesday July 10, 2012 @10:25PM (#4227406)
Or the author could have added 'virtual' to the method declaration and discussed why that code now crashes due to a NULL dereference...
Re:Dereferencing NULL Pointer, without a Seg Fault by repsilat on Tuesday July 10, 2012 @10:33PM (#4227435)
It's disappointing that this works so reliably, even with the simplest of examples. I would have thought that if the compiler could resolve the function call statically it would do away with the vtable lookup, but neither g++ nor Clang do so at any level of optimisation.
Re:Dereferencing NULL Pointer, without a Seg Fault by klodolph on Wednesday July 11, 2012 @12:37AM (#4227743)
Well, you see, that would change the behavior of the program. In order for it to resolve the vtable statically, which it CAN do, it would have to know what kind of vtable the NULL cowPointer has. And the true answer is that the program is already wrong once it accesses the vtable.

To put it another way, such an optimizer would transform incorrect programs into correct programs.

If you write correct programs, the optimization is useless since it only transforms incorrect programs. If you write incorrect programs, the optimization is dangerous since it makes it harder for you to figure out that your program is wrong.

Re:Dereferencing NULL Pointer, without a Seg Fault by repsilat on Wednesday July 11, 2012 @04:31AM (#4228381)
> In order for it to resolve the vtable statically, which it CAN do, it would have to know what kind of vtable the NULL cowPointer has.

Yeah. In retrospect my point doesn't really make any sense at all. Not sure what I was thinking there.

Re:Dereferencing NULL Pointer, without a Seg Fault by DerekL on Tuesday July 10, 2012 @10:34PM (#4227444)
True, it's not dereferencing NULL at the machine level, but in C++ terms, it really is dereferencing the pointer. Evaluating the expression "p" (or "p->m", which is equivalent to "(p).m") is dereferencing. What it isn't doing is reading or writing at or near location 0.