Debian Codegraph @

clang-tools-extra/test/clang-tidy/checkers/bugprone/signal-handler-posix.c

raw
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("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(0);
20 _exit(0);
21 quick_exit(0);
22 signal(0, SIG_DFL);
23 memcpy((void*)10, (const void*)20, 1);
24 }
25
26 void test(void) {
27 signal(SIGINT, handler_good);
28 signal(SIGINT, handler_bad);
29 }