misleading error message

Vincent Lefevre vincent at vinc17.net
Tue Sep 24 13:22:03 CEST 2024


On 2024-09-24 13:07:39 +0200, Vincent Lefevre wrote:
> On 2024-09-24 11:34:05 +0200, Sergey B Kirpichev wrote:
> > On Tue, Sep 24, 2024 at 10:44:48AM +0200, Vincent Lefevre wrote:
> > > It will not do both in general. The "raise (SIGFPE);" will normally
> > > terminate the process with a core dump. The abort() will be called
> > > only if SIGFPE is ignored, but it is dangerous to ignore this signal
> > 
> > No.  If signal handler set - the raise() function shall not return until
> > after the signal handler does.  But then abort() will be called.
> > 
> > So, in quoted issue OP got from OS something like from this toy case,
> > not a core dump at all:
> > sk at note:~ $ cat a.c
> > #include <signal.h>
> > #include <stdlib.h>
> > int main(void)
> > {
> >     raise(SIGFPE);
> >     abort();
> >     return 0;
> > }
> > sk at note:~ $ cc a.c && ./a.out
> > Floating point exception
> 
> Wrong. You do not prove anything with your program.
> The following one shows that "abort();" is not executed.
> 
> $ cat tst.c
> #include <signal.h>
> #include <stdlib.h>
> #include <stdio.h>
> int main(void)
> {
>   raise(SIGFPE);
>   printf("OK\n");
>   abort();
>   return 0;
> }
> $ cc tst.c
> $ ./a.out
> Floating point exception (core dumped)
> 
> And the associated core dump:
> 
> -rw------- 1    319488 2024-09-24 12:58:28 core.283390

Actually the core dump may be Linux-specific. But POSIX still
requires termination as the default action:

https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html

  Signal    Default Action    Description
  SIGFPE    A                 Erroneous arithmetic operation.

where "A" means "Abnormal termination of the process with additional
actions".

It also says for SIGFPE:

  Signal    Code          Reason
  SIGFPE    FPE_INTDIV    Integer divide by zero.
            FPE_INTOVF    Integer overflow.
            FPE_FLTDIV    Floating-point divide by zero.
            FPE_FLTOVF    Floating-point overflow.
            FPE_FLTUND    Floating-point underflow.
            FPE_FLTRES    Floating-point inexact result.
            FPE_FLTINV    Invalid floating-point operation.
            FPE_FLTSUB    Subscript out of range.

So perhaps SIGFPE is the right thing for GMP after all (as this
could be regarded as overflow / out of range). In any case, the
"Floating point exception" message from the system is incorrect,
as SIGFPE is also generated for integer operations.

-- 
Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


More information about the gmp-discuss mailing list