...
| Code Block | ||||
|---|---|---|---|---|
| ||||
#include <signal.h>
#include <stdlib.h>
#include <string.h>
char *err_msg;
void handler(int signum) {
strcpy(err_msg, "SIGINT encountered.");
}
int main(void) {
enum { MAX_MSG_SIZE = 24 };
signal(SIGINT, handler);
err_msg = (char *)malloc(MAX_MSG_SIZE);
if (err_msg == NULL) {
/* Handle error condition. */
}
strcpy(err_msg, "No errors yet.");
/* Main code loop */
return 0;
}
|
Compliant Solution (Writing volatile sig_atomic_t)
...