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");
24 static void __analyzer_register_handler ()
26 signal(SIGINT
, int_handler
);
31 __analyzer_register_handler ();
35 /* "call to 'fprintf' from within signal handler [CWE-479]". */
36 /* { dg-begin-multiline-output "" }
37 NN | fprintf(stderr, "LOG: %s", msg);
38 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
41 | NN | void test (void)
44 | | (1) entry to 'test'
46 | NN | __analyzer_register_handler ();
47 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
49 | | (2) calling '__analyzer_register_handler' from 'test'
51 +--> '__analyzer_register_handler': events 3-4
53 | NN | static void __analyzer_register_handler ()
54 | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~
56 | | (3) entry to '__analyzer_register_handler'
58 | NN | signal(SIGINT, int_handler);
59 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
61 | | (4) registering 'int_handler' as signal handler
66 | (5): later on, when the signal is delivered to the process
68 +--> 'int_handler': events 6-7
70 | NN | static void int_handler(int signum)
73 | | (6) entry to 'int_handler'
75 | NN | custom_logger("got signal");
76 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
78 | | (7) calling 'custom_logger' from 'int_handler'
80 +--> 'custom_logger': events 8-9
82 | NN | void custom_logger(const char *msg)
85 | | (8) entry to 'custom_logger'
87 | NN | fprintf(stderr, "LOG: %s", msg);
88 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
90 | | (9) call to 'fprintf' from within signal handler
92 { dg-end-multiline-output "" { target c } } */
93 /* { dg-begin-multiline-output "" }
94 NN | fprintf(stderr, "LOG: %s", msg);
95 | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
96 'void test()': events 1-2
98 | NN | void test (void)
101 | | (1) entry to 'test'
103 | NN | __analyzer_register_handler ();
104 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
106 | | (2) calling '__analyzer_register_handler' from 'test'
108 +--> 'void __analyzer_register_handler()': events 3-4
110 | NN | static void __analyzer_register_handler ()
111 | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~
113 | | (3) entry to '__analyzer_register_handler'
115 | NN | signal(SIGINT, int_handler);
116 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
118 | | (4) registering 'void int_handler(int)' as signal handler
123 | (5): later on, when the signal is delivered to the process
125 +--> 'void int_handler(int)': events 6-7
127 | NN | static void int_handler(int signum)
130 | | (6) entry to 'int_handler'
132 | NN | custom_logger("got signal");
133 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
135 | | (7) calling 'custom_logger' from 'int_handler'
137 +--> 'void custom_logger(const char*)': events 8-9
139 | NN | void custom_logger(const char *msg)
142 | | (8) entry to 'custom_logger'
144 | NN | fprintf(stderr, "LOG: %s", msg);
145 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
147 | | (9) call to 'int fprintf(FILE*, const char*, ...)' from within signal handler
149 { dg-end-multiline-output "" { target c++ } } */