Jeff King | c8af66a | 2018-07-26 03:21:05 -0400 | [diff] [blame] | 1 | #ifndef BANNED_H |
| 2 | #define BANNED_H |
| 3 | |
| 4 | /* |
| 5 | * This header lists functions that have been banned from our code base, |
| 6 | * because they're too easy to misuse (and even if used correctly, |
| 7 | * complicate audits). Including this header turns them into compile-time |
| 8 | * errors. |
| 9 | */ |
| 10 | |
| 11 | #define BANNED(func) sorry_##func##_is_a_banned_function |
| 12 | |
| 13 | #undef strcpy |
| 14 | #define strcpy(x,y) BANNED(strcpy) |
Jeff King | 1b11b64 | 2018-07-24 05:26:39 -0400 | [diff] [blame] | 15 | #undef strcat |
| 16 | #define strcat(x,y) BANNED(strcat) |
Jeff King | e488b7a | 2018-07-24 05:28:28 -0400 | [diff] [blame] | 17 | #undef strncpy |
| 18 | #define strncpy(x,y,n) BANNED(strncpy) |
Eric Wong | ace5707 | 2019-01-02 09:38:46 +0000 | [diff] [blame] | 19 | #undef strncat |
| 20 | #define strncat(x,y,n) BANNED(strncat) |
Taylor Blau | 60ff56f | 2023-04-24 18:20:26 -0400 | [diff] [blame] | 21 | #undef strtok |
| 22 | #define strtok(x,y) BANNED(strtok) |
| 23 | #undef strtok_r |
| 24 | #define strtok_r(x,y,z) BANNED(strtok_r) |
Jeff King | c8af66a | 2018-07-26 03:21:05 -0400 | [diff] [blame] | 25 | |
Jeff King | cc8fdae | 2018-07-24 05:27:19 -0400 | [diff] [blame] | 26 | #undef sprintf |
| 27 | #undef vsprintf |
Jeff King | cc8fdae | 2018-07-24 05:27:19 -0400 | [diff] [blame] | 28 | #define sprintf(...) BANNED(sprintf) |
| 29 | #define vsprintf(...) BANNED(vsprintf) |
Jeff King | cc8fdae | 2018-07-24 05:27:19 -0400 | [diff] [blame] | 30 | |
Jeff King | 1fbfdf5 | 2020-12-01 13:11:37 -0800 | [diff] [blame] | 31 | #undef gmtime |
| 32 | #define gmtime(t) BANNED(gmtime) |
| 33 | #undef localtime |
| 34 | #define localtime(t) BANNED(localtime) |
| 35 | #undef ctime |
| 36 | #define ctime(t) BANNED(ctime) |
Jeff King | 91aef03 | 2020-12-01 13:11:38 -0800 | [diff] [blame] | 37 | #undef ctime_r |
| 38 | #define ctime_r(t, buf) BANNED(ctime_r) |
Jeff King | 1fbfdf5 | 2020-12-01 13:11:37 -0800 | [diff] [blame] | 39 | #undef asctime |
| 40 | #define asctime(t) BANNED(asctime) |
Jeff King | 91aef03 | 2020-12-01 13:11:38 -0800 | [diff] [blame] | 41 | #undef asctime_r |
| 42 | #define asctime_r(t, buf) BANNED(asctime_r) |
Jeff King | 1fbfdf5 | 2020-12-01 13:11:37 -0800 | [diff] [blame] | 43 | |
Jeff King | c8af66a | 2018-07-26 03:21:05 -0400 | [diff] [blame] | 44 | #endif /* BANNED_H */ |