mirror of
https://github.com/git/git
synced 2024-08-27 19:49:21 +00:00
![Taylor Blau](/assets/img/avatar_default.png)
`strtok()` has a couple of drawbacks that make it undesirable to have any new instances. In addition to being thread-unsafe, it also encourages confusing data flows, where `strtok()` may be called from multiple functions with its first argument as NULL, making it unclear from the immediate context which string is being tokenized. Now that we have removed all instances of `strtok()` from the tree, let's ban `strtok()` to avoid introducing new ones in the future. If new callers should arise, they are encouraged to use `string_list_split_in_place()` (and `string_list_remove_empty_items()`, if applicable). string_list_split_in_place() is not a perfect drop-in replacement for `strtok_r()`, particularly if the caller is processing a string with an arbitrary number of tokens, and wants to process each token one at a time. But there are no instances of this in Git's tree which are more well-suited to `strtok_r()` than the friendlier `string_list_split_in_place()`, so ban `strtok_r()`, too. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
45 lines
1.1 KiB
C
45 lines
1.1 KiB
C
#ifndef BANNED_H
|
|
#define BANNED_H
|
|
|
|
/*
|
|
* This header lists functions that have been banned from our code base,
|
|
* because they're too easy to misuse (and even if used correctly,
|
|
* complicate audits). Including this header turns them into compile-time
|
|
* errors.
|
|
*/
|
|
|
|
#define BANNED(func) sorry_##func##_is_a_banned_function
|
|
|
|
#undef strcpy
|
|
#define strcpy(x,y) BANNED(strcpy)
|
|
#undef strcat
|
|
#define strcat(x,y) BANNED(strcat)
|
|
#undef strncpy
|
|
#define strncpy(x,y,n) BANNED(strncpy)
|
|
#undef strncat
|
|
#define strncat(x,y,n) BANNED(strncat)
|
|
#undef strtok
|
|
#define strtok(x,y) BANNED(strtok)
|
|
#undef strtok_r
|
|
#define strtok_r(x,y,z) BANNED(strtok_r)
|
|
|
|
#undef sprintf
|
|
#undef vsprintf
|
|
#define sprintf(...) BANNED(sprintf)
|
|
#define vsprintf(...) BANNED(vsprintf)
|
|
|
|
#undef gmtime
|
|
#define gmtime(t) BANNED(gmtime)
|
|
#undef localtime
|
|
#define localtime(t) BANNED(localtime)
|
|
#undef ctime
|
|
#define ctime(t) BANNED(ctime)
|
|
#undef ctime_r
|
|
#define ctime_r(t, buf) BANNED(ctime_r)
|
|
#undef asctime
|
|
#define asctime(t) BANNED(asctime)
|
|
#undef asctime_r
|
|
#define asctime_r(t, buf) BANNED(asctime_r)
|
|
|
|
#endif /* BANNED_H */
|