News for hackers. Stuff that matters.
Re:Null Pointer Dereferencing Causes Undefined Behavior by cygx on Tuesday April 21, 2015 @05:59AM (#9413053)
The C standard does not specify the representation of null pointers, nor does it allow arithmetics with invalid pointers.

Eg the conversion (void *)0 might result in a value with all bits set and member access will overflow.

Another example would be hardware that raises a signal when encountering an invalid value during address calculations.

In practice, the address calculation will work as expected (ie I'm unaware of machines where it doesn't). However, an aggressively optimizing compiler migh treat an expression like foo->bar as assert(foo != NULL), which might lead to unintended consequences in worst-case scenarios.

Re:Null Pointer Dereferencing Causes Undefined Behavior by masklinn on Tuesday April 21, 2015 @08:09AM (#9413448)
> However, an aggressively optimizing compiler migh treat an expression like foo->bar as assert(foo != NULL)

In fact most modern optimising compilers do exactly that, and the article does refer to such a behaviour having had security implications in the past.