From 8e055156e390ca255bcfe286726b21936321fd81 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sat, 11 Oct 2025 10:22:50 +0100 Subject: [PATCH] Codefix: Make sure safeguards.h is the last included non-table header. (#14687) --- src/console_cmds.cpp | 5 ++++- src/fontcache/freetypefontcache.cpp | 7 ++++--- src/heightmap.cpp | 6 ++++-- src/openttd.cpp | 4 ++-- src/os/unix/unix.cpp | 9 ++++----- src/saveload/saveload.cpp | 15 ++++++++++++--- src/string.cpp | 8 +++----- src/video/allegro_v.cpp | 4 ++-- src/video/win32_v.cpp | 12 +++++++----- 9 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index d3b086f606..ffc6b13665 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -46,6 +46,10 @@ #include "company_cmd.h" #include "misc_cmd.h" +#if defined(WITH_ZLIB) +#include "network/network_content.h" +#endif /* WITH_ZLIB */ + #include "table/strings.h" #include "safeguards.h" @@ -2176,7 +2180,6 @@ static bool ConNetworkAuthorizedKey(std::span argv) /* Content downloading only is available with ZLIB */ #if defined(WITH_ZLIB) -#include "network/network_content.h" /** Resolve a string to a content type. */ static ContentType StringToContentType(std::string_view str) diff --git a/src/fontcache/freetypefontcache.cpp b/src/fontcache/freetypefontcache.cpp index 0e3de26877..254b722415 100644 --- a/src/fontcache/freetypefontcache.cpp +++ b/src/fontcache/freetypefontcache.cpp @@ -7,6 +7,8 @@ /** @file freetypefontcache.cpp FreeType font cache implementation. */ +#ifdef WITH_FREETYPE + #include "../stdafx.h" #include "../debug.h" @@ -20,14 +22,13 @@ #include "../table/control_codes.h" -#include "../safeguards.h" - -#ifdef WITH_FREETYPE #include #include FT_FREETYPE_H #include FT_GLYPH_H #include FT_TRUETYPE_TABLES_H +#include "../safeguards.h" + /** Font cache for fonts that are based on a freetype font. */ class FreeTypeFontCache : public TrueTypeFontCache { private: diff --git a/src/heightmap.cpp b/src/heightmap.cpp index 9d7a09bf7e..0bbc79cb3d 100644 --- a/src/heightmap.cpp +++ b/src/heightmap.cpp @@ -22,6 +22,10 @@ #include "table/strings.h" +#ifdef WITH_PNG +#include +#endif /* WITH_PNG */ + #include "safeguards.h" /** @@ -72,8 +76,6 @@ static inline uint8_t RGBToGreyscale(uint8_t red, uint8_t green, uint8_t blue) #ifdef WITH_PNG -#include - /** * The PNG Heightmap loader. */ diff --git a/src/openttd.cpp b/src/openttd.cpp index a26aa68a97..4317b99e64 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -88,13 +88,13 @@ #include "table/strings.h" -#include "safeguards.h" - #ifdef __EMSCRIPTEN__ # include # include #endif +#include "safeguards.h" + void CallLandscapeTick(); void DoPaletteAnimations(); void MusicLoop(); diff --git a/src/os/unix/unix.cpp b/src/os/unix/unix.cpp index 36ee069637..5bc89cceac 100644 --- a/src/os/unix/unix.cpp +++ b/src/os/unix/unix.cpp @@ -14,7 +14,6 @@ #include "../../fios.h" #include "../../thread.h" - #include #include #include @@ -26,6 +25,10 @@ #include #endif +#ifdef WITH_ICONV +#include +#endif /* WITH_ICONV */ + #ifdef __EMSCRIPTEN__ # include #endif @@ -85,10 +88,6 @@ bool FiosIsHiddenFile(const std::filesystem::path &path) #ifdef WITH_ICONV -#include -#include "../../debug.h" -#include "../../string_func.h" - std::optional GetCurrentLocale(const char *param); #define INTERNALCODE "UTF-8" diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index f602bd1524..9f759cc7b0 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -56,6 +56,18 @@ # include #endif +#ifdef WITH_LZO +#include +#endif + +#if defined(WITH_ZLIB) +#include +#endif /* WITH_ZLIB */ + +#if defined(WITH_LIBLZMA) +#include +#endif /* WITH_LIBLZMA */ + #include "table/strings.h" #include "../safeguards.h" @@ -2417,7 +2429,6 @@ struct FileWriter : SaveFilter { *******************************************/ #ifdef WITH_LZO -#include /** Buffer size for the LZO compressor */ static const uint LZO_BUFFER_SIZE = 8192; @@ -2546,7 +2557,6 @@ struct NoCompSaveFilter : SaveFilter { ********************************************/ #if defined(WITH_ZLIB) -#include /** Filter using Zlib compression. */ struct ZlibLoadFilter : LoadFilter { @@ -2665,7 +2675,6 @@ struct ZlibSaveFilter : SaveFilter { ********************************************/ #if defined(WITH_LIBLZMA) -#include /** * Have a copy of an initialised LZMA stream. We need this as it's diff --git a/src/string.cpp b/src/string.cpp index 18827e5904..09b3f7250d 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -28,7 +28,10 @@ #ifdef WITH_ICU_I18N /* Required by StrNaturalCompare. */ +# include +# include # include +# include # include "language.h" # include "gfx_func.h" #endif /* WITH_ICU_I18N */ @@ -453,8 +456,6 @@ int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garb #ifdef WITH_ICU_I18N -#include - /** * Search if a string is contained in another string using the current locale. * @@ -601,9 +602,6 @@ bool ConvertHexToBytes(std::string_view hex, std::span bytes) #elif defined(WITH_ICU_I18N) -#include -#include - /** String iterator using ICU as a backend. */ class IcuStringIterator : public StringIterator { diff --git a/src/video/allegro_v.cpp b/src/video/allegro_v.cpp index 424fafa2a9..11f0d63e9b 100644 --- a/src/video/allegro_v.cpp +++ b/src/video/allegro_v.cpp @@ -28,14 +28,14 @@ #include "allegro_v.h" #include -#include "../safeguards.h" - #ifdef _DEBUG /* Allegro replaces SEGV/ABRT signals meaning that the debugger will never * be triggered, so rereplace the signals and make the debugger useful. */ #include #endif +#include "../safeguards.h" + static FVideoDriver_Allegro iFVideoDriver_Allegro; static BITMAP *_allegro_screen; diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp index 728b2be9f9..d8600faa65 100644 --- a/src/video/win32_v.cpp +++ b/src/video/win32_v.cpp @@ -32,6 +32,13 @@ #include #endif +#ifdef WITH_OPENGL +#include +#include "../3rdparty/opengl/glext.h" +#include "../3rdparty/opengl/wglext.h" +#include "opengl.h" +#endif /* WITH_OPENGL */ + #include "../safeguards.h" /* Missing define in MinGW headers. */ @@ -1285,11 +1292,6 @@ void VideoDriver_Win32GDI::Paint() #ifdef WITH_OPENGL -#include -#include "../3rdparty/opengl/glext.h" -#include "../3rdparty/opengl/wglext.h" -#include "opengl.h" - #ifndef PFD_SUPPORT_COMPOSITION # define PFD_SUPPORT_COMPOSITION 0x00008000 #endif