...
Non-Compliant Coding Example
Code Block | ||
---|---|---|
| ||
#include <setjmp.h>
#include <signal.h>
static jmp_buf env;
void int_handler() {
longjmp(env, 1);
}
int main() {
char *foo;
signal(SIGINT, int_handler);
if(setjmp(env) == 0) {
foo = malloc(15);
}
else {
foo = "Signal caught.";
}
return 0;
}
|
Compliant Solution
Signal handlers should be as minimal as possible, only setting a flag where appropriate, and returning.
...