1 | // RUN: %check_clang_tidy %s bugprone-signal-handler %t \ |
2 | // RUN: -config='{CheckOptions: \ |
3 | // RUN: {bugprone-signal-handler.AsyncSafeFunctionSet: "POSIX"}}' \ |
4 | // RUN: -- -isystem %clang_tidy_headers |
5 | |
6 | #include "signal.h" |
7 | #include "stdlib.h" |
8 | #include "stdio.h" |
9 | #include "string.h" |
10 | #include "unistd.h" |
11 | |
12 | void handler_bad(int) { |
13 | printf(format: "1234" ); |
14 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: standard function 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler] |
15 | } |
16 | |
17 | void handler_good(int) { |
18 | abort(); |
19 | _Exit(status: 0); |
20 | _exit(status: 0); |
21 | quick_exit(status: 0); |
22 | signal(sig: 0, SIG_DFL); |
23 | memcpy(dest: (void*)10, src: (const void*)20, n: 1); |
24 | } |
25 | |
26 | void test(void) { |
27 | signal(SIGINT, handler: handler_good); |
28 | signal(SIGINT, handler: handler_bad); |
29 | } |
30 | |