No signal interception when divided by 0

Started by Prokrust, March 09, 2021, 01:23:47 PM

Previous topic - Next topic

Prokrust


#include <stdio.h>
#include <setjmp.h>
#include <stdlib.h>
#include <signal.h>

sig_atomic_t _zmem_sig_ = 0;
void __cdecl zmem_signal_log(int sig) {
exit(_zmem_sig_ = sig);
}
void __cdecl zmem_exit(void) {
if(_zmem_sig_)
printf("EXIT [%i]\n", _zmem_sig_);
}
void zmem_signal_set(void) {
signal(SIGINT, &zmem_signal_log);
signal(SIGILL, &zmem_signal_log);
signal(SIGFPE, &zmem_signal_log);
signal(SIGSEGV, &zmem_signal_log);
signal(SIGTERM, &zmem_signal_log);
signal(SIGABRT, &zmem_signal_log);
atexit(&zmem_exit);
}

int chk_div(int ii) {
//raise(8);
return 777 / ii;
}

int main(int argc, char *argv[]) { (void)argv[argc];
int ii = 0;
printf("Start\n");
zmem_signal_set();
ii = chk_div(0);
return ii;
}

An error occurs at startup:
QuoteStart
CRT: unhandled exception (main) -- terminating
*** Process returned 255 ***
If you uncomment the raise () call, the interception works
I don't want to use to intercept SEH.
PS.
Debug mode
Option "Enable Microsoft extensions" has no effect

Pelle

The current behavior seems consistent with some other compilers on Windows: you can catch floating-point divide-by-zero, but not integer ditto. The C standard says little about the specifics. Can't see a bug here. All I can do is put this on the "wish-list" and hope to get there within the next 25 years (hint: probably not...)
/Pelle