Web lists-archives.com

FPE_FLTSUB where FLT_FLTINV is expected




Hello,

The following code produces FPE_FLTSUB(22) for the signal code whereas all platforms (Linux, Mac, FreeBSD) where I tested it, consistently yield FPE_FLTINV
(which on CYGWIN has a value of 21):

#define _GNU_SOURCE
#include <fenv.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

void sigfpe(int signo, siginfo_t* si, void* ucontext)
{
    printf("code = %d\n", si->si_code);
    _exit(255);
}

int main()
{
    double a = 0, b = 0;
    struct sigaction sa;
    memset(&sa, 0, sizeof(sa));
    sa.sa_sigaction = sigfpe;
    sa.sa_flags = SA_SIGINFO;
    sigaction(SIGFPE, &sa, 0);
    feenableexcept(FE_ALL_EXCEPT);
    printf("%lf", a / b);
    return 0;
}

I suppose that this block of code in exceptions.cc is not particularly correct, and only the last case (STACK_CHECK) actually pertains to the FLTSUB situation,
while all previous labels should be redirected to FPE_FLTINV (which, BTW, seems not being used at all in CYGWIN):

    case STATUS_FLOAT_DENORMAL_OPERAND:
    case STATUS_FLOAT_DIVIDE_BY_ZERO:
    case STATUS_FLOAT_INVALID_OPERATION:
    case STATUS_FLOAT_STACK_CHECK:
      si.si_signo = SIGFPE;
      si.si_code = FPE_FLTSUB;
      break;

Thanks for looking into this!

Regards,

Anton Lavrentiev
Contractor NIH/NLM/NCBI


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple