4 ms·
I don't get it, there is no actual dereferencing going on here, It is just basic addition arithmetic between two values, one of them happens to be 0. Why It is
by shultays 12y ago
I don't get it, there is no actual dereferencing going on here, It is just basic addition arithmetic between two values, one of them happens to be 0. Why It is illegal or "The program running well is pure luck"?
- cygx 12y agoThe 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.