Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: should divide-by-zero generate a SIGFPE?



paul%whooppee.com@localhost (Paul Goyette) writes:

>As some of you have noticed, I've been slowly migrating some of the old 
>src/regress tests to the new atf format.  I've discovered that the test 
>for SIGFPE in src/regress/lib/libc/siginifo/sigfpe/ doesn't work.  It 
>attempts trigger a signal by

>       {
>               double d = strtod("0", NULL);
>               ...
>               sigaction(SIGFPE, &sa, NULL);
>               printf("%g\n", 1 / d);
>               ...

>But the routine specified in sa.sa_sigaction does not get called, and 
>the test fails.


Well, here (netbsd-4/i386, -current/amd64) it does work and aborts with:

assertion "z++ == 0" failed: file "sigfpe.c", line 48, function "sigfpe"

That's because the signal handler will just return to the offending
instruction and retry it, causing another exception that triggers
the assertion. You are supposed to exit from the sigfpe handler
with longjmp() or some equivalent.

Wether you really get exceptions on a specific platform is
hardware dependent, sometimes the compiler needs to generate
extra code. Even wether the sigfpe handler returns to
the faulting instruction or the next instruction depends
on the hardware.

But amd64 should work fine.

-- 
-- 
                                Michael van Elst
Internet: mlelstv%serpens.de@localhost
                                "A potential Snark may lurk in every tree."


Home | Main Index | Thread Index | Old Index