3 ms·
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 res
by cygx 12y ago
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.
- masklinn 12y ago> 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.