Fix: Violation of strict weak ordering in engine name sorter
[openttd-github.git] / src / safeguards.h
blob5351116ecb6064b98db0fc6c2f147348648624b4
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
8 /**
9 * @file safeguards.h A number of safeguards to prevent using unsafe methods.
11 * Unsafe methods are, for example, strndup and strncpy because they may leave the
12 * string without a null termination, but also strdup and strndup because they can
13 * return nullptr and then all strdups would need to be guarded against that instead
14 * of using the current MallocT/ReallocT/CallocT technique of just giving the user
15 * an error that too much memory was used instead of spreading that code though
16 * the whole code base.
19 #ifndef SAFEGUARDS_H
20 #define SAFEGUARDS_H
22 /* Use MallocT instead. */
23 #define malloc SAFEGUARD_DO_NOT_USE_THIS_METHOD
25 /* Use MallocT instead. */
26 #define calloc SAFEGUARD_DO_NOT_USE_THIS_METHOD
28 /* Use ReallocT instead. */
29 #define realloc SAFEGUARD_DO_NOT_USE_THIS_METHOD
31 /* Use stredup instead. */
32 #define strdup SAFEGUARD_DO_NOT_USE_THIS_METHOD
33 #define strndup SAFEGUARD_DO_NOT_USE_THIS_METHOD
35 /* Use strecpy instead. */
36 #define strcpy SAFEGUARD_DO_NOT_USE_THIS_METHOD
37 #define strncpy SAFEGUARD_DO_NOT_USE_THIS_METHOD
39 /* Use strecat instead. */
40 #define strcat SAFEGUARD_DO_NOT_USE_THIS_METHOD
41 #define strncat SAFEGUARD_DO_NOT_USE_THIS_METHOD
43 /* Use seprintf instead. */
44 #define sprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
45 #define snprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
47 /* Use vseprintf instead. */
48 #define vsprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
49 #define vsnprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
51 /* Use fgets instead. */
52 #define gets SAFEGUARD_DO_NOT_USE_THIS_METHOD
54 /* No clear replacement. */
55 #define strtok SAFEGUARD_DO_NOT_USE_THIS_METHOD
57 /* Use our own templated implementation instead of a macro or function with only one type. */
58 #ifdef min
59 #undef min
60 #endif
62 /* Use our own templated implementation instead of a macro or function with only one type. */
63 #ifdef max
64 #undef max
65 #endif
67 /* Use our own templated implementation instead of a macro or function with only one type. */
68 #ifdef abs
69 #undef abs
70 #endif
72 #endif /* SAFEGUARDS_H */