1 /* Verify how paths are printed for signal-handler diagnostics. */
3 /* { dg-options "-fanalyzer -fdiagnostics-show-line-numbers -fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */
4 /* { dg-enable-nn-line-numbers "" } */
5 /* { dg-require-effective-target signal } */
11 extern void body_of_program(void);
13 void custom_logger(const char *msg
)
15 fprintf(stderr
, "LOG: %s", msg
); /* { dg-warning "call to 'fprintf' from within signal handler" "" { target c } } */
16 /* { dg-warning "call to 'int fprintf\\(FILE\\*, const char\\*, ...\\)' from within signal handler" "" { target c++ } .-1 } */
19 static void int_handler(int signum
)
21 custom_logger("got signal");
26 void *ptr
= malloc (1024);
27 signal(SIGINT
, int_handler
);
32 /* "call to 'fprintf' from within signal handler [CWE-479]". */
33 /* { dg-begin-multiline-output "" }
34 NN | fprintf(stderr, "LOG: %s", msg);
35 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
38 | NN | void test (void)
41 | | (1) entry to 'test'
43 | NN | signal(SIGINT, int_handler);
44 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
46 | | (2) registering 'int_handler' as signal handler
51 | (3): later on, when the signal is delivered to the process
53 +--> 'int_handler': events 4-5
55 | NN | static void int_handler(int signum)
58 | | (4) entry to 'int_handler'
60 | NN | custom_logger("got signal");
61 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
63 | | (5) calling 'custom_logger' from 'int_handler'
65 +--> 'custom_logger': events 6-7
67 | NN | void custom_logger(const char *msg)
70 | | (6) entry to 'custom_logger'
72 | NN | fprintf(stderr, "LOG: %s", msg);
73 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
75 | | (7) call to 'fprintf' from within signal handler
77 { dg-end-multiline-output "" { target c } } */
78 /* { dg-begin-multiline-output "" }
79 NN | fprintf(stderr, "LOG: %s", msg);
80 | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
81 'void test()': events 1-2
83 | NN | void test (void)
86 | | (1) entry to 'test'
88 | NN | signal(SIGINT, int_handler);
89 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
91 | | (2) registering 'void int_handler(int)' as signal handler
96 | (3): later on, when the signal is delivered to the process
98 +--> 'void int_handler(int)': events 4-5
100 | NN | static void int_handler(int signum)
103 | | (4) entry to 'int_handler'
105 | NN | custom_logger("got signal");
106 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
108 | | (5) calling 'custom_logger' from 'int_handler'
110 +--> 'void custom_logger(const char*)': events 6-7
112 | NN | void custom_logger(const char *msg)
115 | | (6) entry to 'custom_logger'
117 | NN | fprintf(stderr, "LOG: %s", msg);
118 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
120 | | (7) call to 'int fprintf(FILE*, const char*, ...)' from within signal handler
122 { dg-end-multiline-output "" { target c++ } } */