Debian Codegraph @

gcc/testsuite/gcc.dg/analyzer/signal-2.c

raw
1 /* Example of a bad call within a signal handler.
2 'handler' calls 'custom_logger' which calls 'fprintf', and 'fprintf' is
3 not allowed from a signal handler. */
4 /* { dg-require-effective-target signal } */
5
6 #include <stdio.h>
7 #include <signal.h>
8
9 extern void body_of_program(void);
10
11 int logging = 1;
12
13 void custom_logger(const char *msg)
14 {
15 if (logging)
16 fprintf(stderr, "LOG: %s", msg); /* { dg-warning "call to 'fprintf' from within signal handler" } */
17 }
18
19 static void handler(int signum)
20 {
21 custom_logger("got signal");
22 }
23
24 int main(int argc, const char *argv)
25 {
26 custom_logger("started");
27
28 signal(SIGINT, handler); /* { dg-message "registering 'handler' as signal handler" } */
29
30 body_of_program();
31
32 custom_logger("stopped");
33
34 return 0;
35 }