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

source code of clang-tools-extra/test/clang-tidy/checkers/bugprone/signal-handler-minimal.c