From 6c1c042637ac77dcd944f57c403040ffcb5414f3 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Fri, 24 Apr 2026 11:15:32 +0200 Subject: [PATCH] =?UTF-8?q?build:=20a=C3=AFlla=20la=20implementaci=C3=B3?= =?UTF-8?q?=20de=20stb=5Fimage=5Fwrite=20en=20un=20TU=20propi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit screenshot.cpp ara només inclou les declaracions de stb_image_write.h; la macro STB_IMAGE_WRITE_IMPLEMENTATION viu a un .cpp nou dins de source/external/, que ja està exclòs del pre-commit hook (clang-format i clang-tidy) i cobert pel seu .clang-tidy amb Checks: '-*'. Així podem retirar la desactivació global de clang-analyzer-optin.portability .UnixAPI i el check queda actiu arreu del nostre propi codi. --- .clang-tidy | 9 +++------ CMakeLists.txt | 1 + source/core/rendering/screenshot.cpp | 2 -- source/external/stb_image_write_impl.cpp | 13 +++++++++++++ 4 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 source/external/stb_image_write_impl.cpp diff --git a/.clang-tidy b/.clang-tidy index 166f435..6193962 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -9,14 +9,11 @@ Checks: - -bugprone-easily-swappable-parameters - -bugprone-narrowing-conversions - -modernize-avoid-c-arrays,-warnings-as-errors - # Fals positius recurrents en codi C de tercers dins source/external/. + # Fals positiu recurrent en codi C de tercers (source/external/stb_vorbis.c). # HeaderFilterRegex no aplica a clang-analyzer-*, així que cal desactivar - # explícitament. El primer: inferència sobre variables locals de legacy C - # (stb_vorbis.c). El segon: ús de malloc() a stb_image_write.h, que - # l'analitzador marca com a possible "size=0" en rutes que a la pràctica - # no es donen. + # explícitament. El check d'inferència sobre variables locals de legacy C + # genera reports que no reflecteixen bugs reals. - -clang-analyzer-core.UndefinedBinaryOperatorResult - - -clang-analyzer-optin.portability.UnixAPI WarningsAsErrors: '*' # Headers nostres (excloem source/external/ que conté dependències de tercers no editables) diff --git a/CMakeLists.txt b/CMakeLists.txt index c327897..761dc9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,6 +68,7 @@ set(APP_SOURCES source/core/rendering/render_info.cpp source/core/rendering/gif.cpp source/core/rendering/screenshot.cpp + source/external/stb_image_write_impl.cpp source/core/rendering/surface.cpp source/core/rendering/text.cpp source/core/rendering/sprite/sprite.cpp diff --git a/source/core/rendering/screenshot.cpp b/source/core/rendering/screenshot.cpp index f8ea2f6..c520563 100644 --- a/source/core/rendering/screenshot.cpp +++ b/source/core/rendering/screenshot.cpp @@ -7,7 +7,6 @@ #include #include -#define STB_IMAGE_WRITE_IMPLEMENTATION #include "external/stb_image_write.h" namespace Screenshot { @@ -43,7 +42,6 @@ namespace Screenshot { const std::uint32_t B = P & 0xFF; buffer[i] = R | (G << 8) | (B << 16) | (A << 24); } - // NOLINTNEXTLINE(clang-analyzer-optin.portability.UnixAPI) — fals positiu dins de stb_image_write return stbi_write_png(filepath.c_str(), width, height, 4, buffer, width * 4) != 0; } diff --git a/source/external/stb_image_write_impl.cpp b/source/external/stb_image_write_impl.cpp new file mode 100644 index 0000000..9036100 --- /dev/null +++ b/source/external/stb_image_write_impl.cpp @@ -0,0 +1,13 @@ +// Unitat de compilació aïllada per a la implementació de stb_image_write. +// Viu dins de source/external/ perquè el `.clang-tidy` d'aquesta carpeta +// desactiva tots els checks (com fa per stb_vorbis.c) i el pre-commit hook +// ja filtra aquesta ruta de clang-format / clang-tidy. Així els fals +// positius de clang-analyzer-* dins de codi de tercers no afecten el +// nostre codi, que continua tenint tots els checks actius. +// +// La resta del codi inclou només el header (sense la macro d'implementació), +// que queda només amb declaracions — clang-analyzer no pot trobar cap bug +// dins d'una declaració, així que l'inclusió és innòcua. + +#define STB_IMAGE_WRITE_IMPLEMENTATION +#include "external/stb_image_write.h"