From df29e6046f71e2d310eed202ff2f4b935aa26046 Mon Sep 17 00:00:00 2001 From: LibretroAdmin Date: Fri, 11 Sep 2026 06:32:42 +0000 Subject: [PATCH] tools: fail a .c that uses strlcpy without including compat/strl.h modeline_edid.c called strlcpy with no and reached master: glibc 2.38 declares strlcpy and strlcat itself, so it built clean here and passed both syntax-check passes, while MXE, clang and the webOS toolchain - which have only libretro-common's declaration - did not. Neither pass could have caught it, since both ask the host's headers what exists. A grep can, and does not care what the host provides: a .c that uses strlcpy, strlcat, strlcpy_lit, strlcat_lit or strcasestr must include the compat header itself rather than lean on whatever a project header dragged in, which is the standing rule anyway. It runs as pass 0 of tools/mingw_syntax_check.sh, so it fires on the files being checked before delivery and costs nothing. Fourteen files were leaning on the transitive declaration and now include it directly: the font driver and its freetype renderer, the widgets, vulkan_common, the GX2, PS2 and OGA drivers, the Android display server, the screensaver and cancel callbacks, the audio driver, the test input and joypad drivers, and the webOS Wayland helper. No behaviour changes; the ones this host can build were checked, and the failures that remain there are the ones master already had. --- audio/audio_driver.c | 2 ++ gfx/common/vulkan_common.c | 2 ++ gfx/display_servers/dispserv_android.c | 2 ++ gfx/drivers/gx2_gfx.c | 2 ++ gfx/drivers/oga_gfx.c | 2 ++ gfx/drivers/ps2_gfx.c | 2 ++ gfx/drivers_font_renderer/freetype.c | 2 ++ gfx/font_driver.c | 2 ++ gfx/gfx_widgets.c | 2 ++ input/common/wayland_common_webos.c | 2 ++ input/drivers/test_input.c | 2 ++ input/drivers_joypad/test_joypad.c | 2 ++ menu/cbs/menu_cbs_cancel.c | 2 ++ menu/menu_screensaver.c | 2 ++ tools/mingw_syntax_check.sh | 32 +++++++++++++++++++++++++- 15 files changed, 59 insertions(+), 1 deletion(-) diff --git a/audio/audio_driver.c b/audio/audio_driver.c index fa16b0c72f..5f061565f2 100644 --- a/audio/audio_driver.c +++ b/audio/audio_driver.c @@ -59,6 +59,8 @@ #include #include +#include + #ifdef HAVE_THREADS #include "audio_thread_wrapper.h" #endif diff --git a/gfx/common/vulkan_common.c b/gfx/common/vulkan_common.c index 37339f51a9..118caac880 100644 --- a/gfx/common/vulkan_common.c +++ b/gfx/common/vulkan_common.c @@ -48,6 +48,8 @@ #ifdef _WIN32 #include + +#include #endif #define VENDOR_ID_AMD 0x1002 diff --git a/gfx/display_servers/dispserv_android.c b/gfx/display_servers/dispserv_android.c index d33607c53b..5663cb7880 100644 --- a/gfx/display_servers/dispserv_android.c +++ b/gfx/display_servers/dispserv_android.c @@ -20,6 +20,8 @@ #include #include +#include + #include "../../verbosity.h" #include "../video_display_server.h" #include "../../frontend/drivers/platform_unix.h" diff --git a/gfx/drivers/gx2_gfx.c b/gfx/drivers/gx2_gfx.c index dfd05bf09a..8024051559 100644 --- a/gfx/drivers/gx2_gfx.c +++ b/gfx/drivers/gx2_gfx.c @@ -27,6 +27,8 @@ #include #include +#include + #include "../../driver.h" #include "../../configuration.h" #include "../../verbosity.h" diff --git a/gfx/drivers/oga_gfx.c b/gfx/drivers/oga_gfx.c index 9c165433c9..7bc188aa41 100644 --- a/gfx/drivers/oga_gfx.c +++ b/gfx/drivers/oga_gfx.c @@ -30,6 +30,8 @@ #include +#include + #ifdef HAVE_CONFIG_H #include "../../config.h" #endif diff --git a/gfx/drivers/ps2_gfx.c b/gfx/drivers/ps2_gfx.c index 1502d4e73a..277ee59b21 100644 --- a/gfx/drivers/ps2_gfx.c +++ b/gfx/drivers/ps2_gfx.c @@ -28,6 +28,8 @@ #include #include +#include + #include "../video_defines.h" #include "../../driver.h" #include "../../retroarch.h" diff --git a/gfx/drivers_font_renderer/freetype.c b/gfx/drivers_font_renderer/freetype.c index 599fad416c..5ea11d9d99 100644 --- a/gfx/drivers_font_renderer/freetype.c +++ b/gfx/drivers_font_renderer/freetype.c @@ -56,6 +56,8 @@ static FcConfig *fc_config = NULL; #ifdef WIIU #include + +#include #endif #include FT_FREETYPE_H diff --git a/gfx/font_driver.c b/gfx/font_driver.c index 0d2803bb24..476f0575ee 100644 --- a/gfx/font_driver.c +++ b/gfx/font_driver.c @@ -31,6 +31,8 @@ #include "video_thread_wrapper.h" #include +#include + /* ------------------------------------------------------------------ * Shared font file bytes. * diff --git a/gfx/gfx_widgets.c b/gfx/gfx_widgets.c index 25a8c7694d..ca07b3486a 100644 --- a/gfx/gfx_widgets.c +++ b/gfx/gfx_widgets.c @@ -29,6 +29,8 @@ #include #include +#include + #include "gfx_display.h" #include "gfx_widgets.h" #include "font_driver.h" diff --git a/input/common/wayland_common_webos.c b/input/common/wayland_common_webos.c index 1fda1bc497..7a492fa610 100644 --- a/input/common/wayland_common_webos.c +++ b/input/common/wayland_common_webos.c @@ -43,6 +43,8 @@ #ifdef HAVE_USERLAND #include + +#include #include "formats/rjson.h" HContext *g_register_ctx = NULL; HContext *g_screensaver_ctx = NULL; diff --git a/input/drivers/test_input.c b/input/drivers/test_input.c index 734f072f5b..c4de946507 100644 --- a/input/drivers/test_input.c +++ b/input/drivers/test_input.c @@ -26,6 +26,8 @@ #include #include +#include + #include "../input_driver.h" #include "../input_keymaps.h" #include "../../verbosity.h" diff --git a/input/drivers_joypad/test_joypad.c b/input/drivers_joypad/test_joypad.c index daca0b8563..4599bb057a 100644 --- a/input/drivers_joypad/test_joypad.c +++ b/input/drivers_joypad/test_joypad.c @@ -32,6 +32,8 @@ #include #include +#include + #include "../../config.def.h" #include "../../verbosity.h" #include "../input_driver.h" diff --git a/menu/cbs/menu_cbs_cancel.c b/menu/cbs/menu_cbs_cancel.c index 4fd2f823f4..896eb2cdef 100644 --- a/menu/cbs/menu_cbs_cancel.c +++ b/menu/cbs/menu_cbs_cancel.c @@ -16,6 +16,8 @@ #include #include +#include + #include "../menu_driver.h" #include "../menu_cbs.h" #include "../../audio/audio_driver.h" diff --git a/menu/menu_screensaver.c b/menu/menu_screensaver.c index ddfe0048ed..f6835a56e0 100644 --- a/menu/menu_screensaver.c +++ b/menu/menu_screensaver.c @@ -22,6 +22,8 @@ #include #include +#include + #include "../verbosity.h" #if defined(HAVE_CONFIG_H) diff --git a/tools/mingw_syntax_check.sh b/tools/mingw_syntax_check.sh index 5d45eaef84..e08367381a 100755 --- a/tools/mingw_syntax_check.sh +++ b/tools/mingw_syntax_check.sh @@ -78,9 +78,39 @@ C89FLAGS="-fsyntax-only -std=c89 -ansi -pedantic -Werror=pedantic \ C89CC_WIN32="${C89CC_WIN32:-i686-w64-mingw32-gcc}" command -v "$C89CC_WIN32" >/dev/null 2>&1 || C89CC_WIN32="" +# Pass 0: the declaration a compiler here cannot miss. +# +# glibc 2.38 declares strlcpy and strlcat itself, so a .c that uses +# them without including compiles clean on this box +# and on both passes below, then fails on MXE, clang and the webOS +# toolchain, where the only declaration is libretro-common's. That is +# how it reached master in modeline_edid.c. A grep is the only check +# that does not depend on what the host's headers happen to provide: +# a file that uses one of these must include the compat header +# itself, not lean on whatever a project header dragged in. +check_compat_include() +{ + f="$1" + miss="" + if grep -qE '\b(strlcpy|strlcat|strlcpy_lit|strlcat_lit)[[:space:]]*\(' "$f" \ + && ! grep -q 'compat/strl\.h' "$f"; then + miss="compat/strl.h" + fi + if grep -qE '\bstrcasestr[[:space:]]*\(' "$f" \ + && ! grep -q 'compat/strcasestr\.h' "$f"; then + miss="$miss compat/strcasestr.h" + fi + [ -z "$miss" ] && return 0 + echo "FAIL [decl] $f" + echo " uses a libretro-common string helper without including:$miss" \ + | sed 's/^/ /' + return 1 +} + fail=0; n=0 for f in $FILES; do n=$((n+1)) + check_compat_include "$f" || fail=1 # Only real errors, not warnings. A missing header named without a # path (d3dkmthk.h: an optional platform header this box lacks) is # forgiven; a missing header with a path component (../companion/x.h: @@ -121,5 +151,5 @@ for f in $FILES; do echo "FAIL [c89] $f"; echo "$err" | sed 's/^/ /'; fail=1 fi done -[ $fail = 0 ] && echo "ok: $n translation units clean (win32 gnu99 + linux c89 pedantic)" +[ $fail = 0 ] && echo "ok: $n translation units clean (compat decls + win32 gnu99 + linux c89 pedantic)" exit $fail