@safe and null dereferencing

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 27 12:16:57 PDT 2017


On 7/27/17 2:46 PM, Jonathan M Davis via Digitalmars-d wrote:
> 
> However, one issue that has been brought up from time to time and AFAIK has
> never really been addressed is that apparently if an object is large enough,
> when you access one of its members when the pointer is null, you won't get a
> segfault (I think that it was something like if the object was greater than
> a page in size). So, as I understand it, ludicrously large objects _could_
> result in @safety problems with null pointers. This would not happen in
> normal code, but it can happen. And if we want @safe to make the guarantees
> that it claims, we really should either disallow such objects or insert null
> checks for them. For smaller objects though, what's the point? It buys us
> nothing if the hardware is already doing it, and the only hardware that
> wouldn't do it should be too old to matter at this point.


Yes: https://issues.dlang.org/show_bug.cgi?id=5176

There is a way to "fix" this: any time you access an object field that 
goes outside the page size, do a null check on the base pointer.

-Steve


More information about the Digitalmars-d mailing list