News for hackers. Stuff that matters.
Re:“Unexplainable” core dump (2011) by krackers on Tuesday January 03, 2023 @08:30PM (#34240719)
Wait, the compiler can do that? I thought only dereferencing a null pointer gives undefined behavior, just checking if a pointer is 0 or not shold be valid?

Yeah based on https://joelaro.wordpress.com/2015/09/30/gcc-optimization-fd... the assumption is that if the pointer was previously dereferenced, it can be assumed to be non-null, and hence all subsequent null-checks can be elided.

Based on https://news.ycombinator.com/item?id=17360772, the case in which this actually makes a difference is an address offset like

   int *n = &param->length
The compiler knows the structure so it can just inline the offset, but the optimizer considers this as being non-null.
Re:“Unexplainable” core dump (2011) by 3836293648 on Wednesday January 04, 2023 @12:51AM (#34242472)
You can check if the address is 0, but the value of the nullptr is implementation definied behaviour. You can have a system where the null pointer is 4.

And address 0 isn't too special on a machine level either. Embedded systems have valid data to read and write there.