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.
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.