Versions Compared

Key

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

...

Code Block
bgColor#FFcccc
#include <stdio.h>
#include <stdlib.h>

void exit1(void) {
   if(<expr> (/* condition */) {
      /* ...cleanup code... */
      exit(0);
   }
}

int main (void) {
    atexit(exit1);
    /* ...program code... */
    exit(0);
}

Compliant

...

Solution

_Exit() and abort() will both immediately halt program execution, and may be used within functions registered by atexit().

...

Code Block
bgColor#ccccFF
#include <stdio.h>
#include <stdlib.h>

void exit1(void) {
   if(<expr> (/* condition */) {
      /* ...cleanup code... */
      _Exit(0);
   }
}

int main (void) {
    atexit(exit1);
    /* ...program code... */
    exit(0);
}

Risk Assessment

Multiple calls to exit() are unlikely, and at worst will only cause denial of service attacks or abnormal program termination.

...