OpenTTD Source 20250311-master-g40ddc03423
safeguards.h
Go to the documentation of this file.
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 */
7
16#ifndef SAFEGUARDS_H
17#define SAFEGUARDS_H
18
19/* Use std::vector/std::unique_ptr/new instead. */
20#define malloc SAFEGUARD_DO_NOT_USE_THIS_METHOD
21#define calloc SAFEGUARD_DO_NOT_USE_THIS_METHOD
22#define realloc SAFEGUARD_DO_NOT_USE_THIS_METHOD
23
24/* Use std::string instead. */
25#define strdup SAFEGUARD_DO_NOT_USE_THIS_METHOD
26#define strndup SAFEGUARD_DO_NOT_USE_THIS_METHOD
27
28/* Use strecpy instead. */
29#define strcpy SAFEGUARD_DO_NOT_USE_THIS_METHOD
30#define strncpy SAFEGUARD_DO_NOT_USE_THIS_METHOD
31
32/* Use std::string concatenation/fmt::format instead. */
33#define strcat SAFEGUARD_DO_NOT_USE_THIS_METHOD
34#define strncat SAFEGUARD_DO_NOT_USE_THIS_METHOD
35
36/* Use fmt::format instead. */
37#define sprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
38#define snprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
39
40/* Use fmt::format instead. */
41#define vsprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
42#define vsnprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
43
44/* Use fgets instead. */
45#define gets SAFEGUARD_DO_NOT_USE_THIS_METHOD
46
47/* No clear replacement. */
48#define strtok SAFEGUARD_DO_NOT_USE_THIS_METHOD
49
50/* Use fmt::print instead. */
51#define printf SAFEGUARD_DO_NOT_USE_THIS_METHOD
52#define fprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
53#define puts SAFEGUARD_DO_NOT_USE_THIS_METHOD
54#define fputs SAFEGUARD_DO_NOT_USE_THIS_METHOD
55#define putchar SAFEGUARD_DO_NOT_USE_THIS_METHOD
56
57/* Use our own templated implementation instead of a macro or function with only one type. */
58#ifdef min
59#undef min
60#endif
61
62/* Use our own templated implementation instead of a macro or function with only one type. */
63#ifdef max
64#undef max
65#endif
66
67/* Use our own templated implementation instead of a macro or function with only one type. */
68#ifdef abs
69#undef abs
70#endif
71
72#if defined(NETWORK_CORE_OS_ABSTRACTION_H) && defined(_WIN32)
73/* Use NetworkError::GetLast() instead of errno, or do not (indirectly) include network/core/os_abstraction.h.
74 * Winsock does not set errno, but one should rather call WSAGetLastError. NetworkError::GetLast abstracts that away. */
75#ifdef errno
76#undef errno
77#endif
78#define errno SAFEGUARD_DO_NOT_USE_THIS_METHOD
79
80/* Use NetworkError::AsString() instead of strerror, or do not (indirectly) include network/core/os_abstraction.h.
81 * Winsock errors are not handled by strerror, but one should rather call FormatMessage. NetworkError::AsString abstracts that away. */
82#define strerror SAFEGUARD_DO_NOT_USE_THIS_METHOD
83#endif /* defined(NETWORK_CORE_OS_ABSTRACTION_H) && defined(_WIN32) */
84
85#endif /* SAFEGUARDS_H */