Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#ffcccc
volatile sig_atomic_t denom;

void sighandle(int s){
  /* Fix the offending volatile */                   
  if (denom == 0) {
    denom == 1;
  }
  /* Everything is ok */
  return;
}

int main(int argc, char *argv[]){
  if (argc < 2) {
    return 0;
  }

  int result = 0;
  denom = atoi(int)strtol(argv[1], (char **)NULL, 10);

  signal(SIGFPE,(*sighandle));

  result = 100/denom;
  return 0;
}

...

Compliant Solution

Code Block
bgColor#ffcccc#ccccff
volatile sig_atomic_t denom;

void sighandle(int s){
  /* No recovery */
  abort();
}

int main(int argc, char *argv[]){
  if (argc < 2) {
    return 0;
  }

  int result = 0;
  denom = (int)strtol(argv[1], (char **)NULL, 10);

  signal(SIGFPE,(*sighandle));

  result = 100/denom;
  return 0;
}

The only portably safe way to leave a SIGFPE, SIGILL, or SIGSEGV handler is through abort() or /_Exit().

...