| 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 |
|
| 11 |
void handler_bad1(int) { |
| 12 |
_exit(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 |
|
| 16 |
void handler_bad2(int) { |
| 17 |
void *dst; |
| 18 |
const void *src; |
| 19 |
memcpy(dst, src, 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 |
|
| 23 |
void handler_good(int) { |
| 24 |
abort(); |
| 25 |
_Exit(0); |
| 26 |
quick_exit(0); |
| 27 |
signal(0, SIG_DFL); |
| 28 |
} |
| 29 |
|
| 30 |
void test(void) { |
| 31 |
signal(SIGINT, handler_bad1); |
| 32 |
signal(SIGINT, handler_bad2); |
| 33 |
signal(SIGINT, handler_good); |
| 34 |
} |