I feel like this is a stupid question, but I have found zero information about the topic (not here nor anywhere), so here's the question:
Context (what you probably already know): SIGFPE
exceptions and si_code
field
In POSIX/Linux we have a particular kind of signal called SIGFPE
(that although its name, it's used both for floating-point and integer arithmetic errors). When we register a signal handler for SIGFPE
using sigaction()
, our handler also receives a field called si_code
that explains why the particular SIGFPE
exception has been raised. One of the possible si_code
values is, for instance, FPE_INTDIV
, and you can quickly test it by dividing an int
by 0
.
The problem: what about FPE_INTOVF
?
My question is about a particular si_code
, that is FPE_INTOVF
. This code is described as Value signalling integer overflow in case of SIGFPE signal
.
The problem is that I have never encountered an example of this signal being raised, nor I found a way to make the OS raise this kind of signal: when I do an integer overflow in C, no SIGFPE
exception is thrown. But the FPE_INTOVF
value for SIGFPE
is a kind of hint that it's maybe possible to make the host throw in case of integer overflows (like it already does for integer division by zero).
The question:
Is FPE_INTOVF
unusable? Is it just a place-holder for a type of signal that no POSIX-compliant OS has ever implemented? Or is it possible to instruct the OS to throw this kind of signal in case of integer overflow?
I'm really interested in catching FPE_INTOVF
signals from a C program using sigaction()
.
P.S.: I recognize that unsigned integer overflow is not technically an error in C (it doesn't exist at all in C, since all unsigned integer arithmetic has "wrapping" behavior), but signed integer overflow is indeed undefined behavior, so I expect that FPE_INTOVF
handles the latter.