Optimization of null pointer dereferences has resulted in security 
vulnerabilities in the Linux kernel:

http://lwn.net/Articles/342330/

I don't think it's responsible for C++ programmers not to consider the 
undefined behavior of null dereference a real hazard.

Patrick

comex <[email protected]> wrote:
>On Wed, Mar 5, 2014 at 11:42 PM, Patrick Walton <[email protected]>
>wrote:
>> Dereference of a null pointer is memory-unsafe due to being undefined
>> behavior. You can't count on dereference of nullptr resulting in a
>load of
>> address zero: the optimizer is free to (and often does) remove that
>load and
>> any code following it. This means that, for example, clang will
>cheerfully
>> allow you to fall off the end of a function after dereferencing a
>moved
>> pointer.
>
>True.  I have never seen this in a real program (and if I try to test
>it by moving a unique_ptr and then dereferencing it, clang generates a
>ud2, although it does not for just dereferencing 0), but it is
>possible.  Still, I don't think most C++ programmers would consider it
>a big deal.

-- 
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to