NO

Author Topic: No signal interception when divided by 0  (Read 2172 times)

Offline Prokrust

  • Member
  • *
  • Posts: 10
No signal interception when divided by 0
« on: March 09, 2021, 01:23:47 PM »
Code: [Select]
#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:
Quote
Start
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
« Last Edit: March 09, 2021, 01:55:14 PM by Prokrust »

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: No signal interception when divided by 0
« Reply #1 on: March 10, 2021, 02:00:56 PM »
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