Le 31/05/2012 03:06, Artur Skawina a écrit :
On 05/31/12 00:21, Jonathan M Davis wrote:
Now, it's perfectly possible to design code which never checks for null
pointers and if a null pointer is dereferenced throws an Exception and
attempts to recover from it (assuming that it's possible to detect the
dereference and throw at that point, which AFAIK is impossible with segfaults
- maybe it could be done on Windows with its Access Violations, but segfaults
trigger a signal handler, and you're screwed at that point). But writing code

No, it's easily recoverable. That does not mean however that it would be a good
idea to map segfaults to exceptions as a language feature. And dereferencing a
null pointer is *not* guaranteed to trap, all you need is a large enough offset
and you will get silent data corruption.

    int i = 42;
    auto j = cast(size_t)&i;

    ubyte* p = null;
    p[j] = 13;
    assert(i!=42); // oops

artur

Most system protect at least the first page (the first 4Kb ). For other it is doable within druntime with page protection.

For bigger stuff, they have to be forbidden in @safe code or runtime check should be added.

Reply via email to