dereferencing null

H. S. Teoh hsteoh at quickfur.ath.cx
Sat Mar 3 20:14:45 PST 2012


On Sun, Mar 04, 2012 at 04:29:27AM +0100, Adam D. Ruppe wrote:
> On Sunday, 4 March 2012 at 03:15:19 UTC, Sandeep Datta wrote:
> >All we have to do now is provide a more specific exception (say
> >NullReferenceException) so that the programmer has the ability to
> >provide a specific exception handler for NullReferenceException etc.
> 
> Looks like it is pretty easy to do. Check out
> 
> dmd2/src/druntime/src/rt/deh.d
> 
> The Access Violation error is thrown on about
> line 635. There's a big switch that handles a bunch
> of errors.
> 
> >I gave it a try on Linux but unfortunately it leads to a segfault
> 
> Yeah, Linux does it as a signal which someone has tried to turn into
> an exception before, which kinda works but is easy to break. (I don't
> remember exactly why it didn't work right, but there were problems.)

Yeah, according to the Posix specs, trying to continue execution after
catching SIGSEGV or SIGILL is ... to say the least, extremely dangerous.
Basically you'll have to unwind the stack and run the rest of the
program inside signal handler context, which means certain operations
(like calling signal unsafe syscalls) are not guaranteed to do what
you'd expect.

Of course, there are ways around it, but it does depend on the specific
way Linux implements signal handling, which is not guaranteed to not
change across Linux versions (because it's not part of the Posix spec).
So it would be very fragile, and prone to nasty bugs.


T

-- 
This is a tpyo.


More information about the Digitalmars-d mailing list