Catching a hot potato

Andrew Wiley wiley.andrew.j at gmail.com
Sun Oct 16 22:37:53 PDT 2011


On Sun, Oct 16, 2011 at 11:54 PM, Gor Gyolchanyan <
gor.f.gyolchanyan at gmail.com> wrote:

> If the user tries to read unallocated memory, the memory can't
> possibly get corrupted, since nothing is getting changed.
> If the user tried to write to unallocated memory, the segfault should
> _prevent_ it by throwing an OS-level exception (the sigsegv). Throwing
> if _after_ the invalid write makes no sense. You can't save anything,
> because your own data is not touched. Depending on the implementation,
> either some other process's memory would be touched or nothing at all
> (internally unmapped region).
> I think the rumors of corrupted memory after sigsegv is boloney.
> Otherwise the whole sigsegv idea is pointless (you could just as well
> get terminated right away).


The problem is that there's no guarantee that you *only* wrote outside your
allocated virtual memory. You could have a bad pointer, overwrite half your
program's data, then hit an invalid address and segfault. There are many
scenarios in which bad writes *don't* cause segfaults (they may be
incorrect, but they're still legal), so you can't really assume much about
your program's state when you segfault.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20111017/971a77d2/attachment.html>


More information about the Digitalmars-d mailing list