From 9257af75706d3ed1833ceb54e574e96871e3c2d0 Mon Sep 17 00:00:00 2001 From: Jehan Date: Wed, 1 Apr 2026 15:58:00 +0200 Subject: [PATCH] app: do not use variable length arrays. Fixing in the gimp-macos-inhouse: [arm64] job: > ../app/core/gimpbrush-transform.cc:869:17: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension] Also adding some asserts in some places where we rely on the MAX_CHANNELS constant so that we will quickly detect if this variable needs to be further bumped in the future (especially as we will add CMYK+ support as backend format). --- app/core/core-types.h | 2 +- app/core/gimpbrush-transform.cc | 7 +++++-- app/core/gimppickable-auto-shrink.c | 2 +- app/core/gimppickable-contiguous-region.cc | 5 +++++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/core/core-types.h b/app/core/core-types.h index 990be94727..75a8526f0b 100644 --- a/app/core/core-types.h +++ b/app/core/core-types.h @@ -30,7 +30,7 @@ /* former base/ defines */ -#define MAX_CHANNELS 4 +#define MAX_CHANNELS 5 #define RED 0 #define GREEN 1 diff --git a/app/core/gimpbrush-transform.cc b/app/core/gimpbrush-transform.cc index 45673cd4f2..e36475b351 100644 --- a/app/core/gimpbrush-transform.cc +++ b/app/core/gimpbrush-transform.cc @@ -841,6 +841,9 @@ gimp_brush_transform_blur (GimpTempBuf *buf, if (rw <= 0 || rh <= 0) return; + /* Making sure we have enough elements for acc array. */ + g_return_if_fail (components <= MAX_CHANNELS); + sums = g_new (Sums, width * height * components); gegl_parallel_distribute_range ( @@ -866,7 +869,7 @@ gimp_brush_transform_blur (GimpTempBuf *buf, gint weighted_sum; gint leading_sum; gint leading_weighted_sum; - } acc[components]; + } acc[MAX_CHANNELS]; memset (acc, 0, sizeof (acc)); @@ -946,7 +949,7 @@ gimp_brush_transform_blur (GimpTempBuf *buf, gfloat weighted_sum; gint leading_sum; gint trailing_sum; - } acc[components]; + } acc[MAX_CHANNELS]; memset (acc, 0, sizeof (acc)); diff --git a/app/core/gimppickable-auto-shrink.c b/app/core/gimppickable-auto-shrink.c index 7ddbee227c..c6b6186b51 100644 --- a/app/core/gimppickable-auto-shrink.c +++ b/app/core/gimppickable-auto-shrink.c @@ -72,7 +72,7 @@ gimp_pickable_auto_shrink (GimpPickable *pickable, GeglBuffer *buffer; GeglRectangle rect; ColorsEqualFunc colors_equal_func; - guchar bgcolor[MAX_CHANNELS] = { 0, 0, 0, 0 }; + guchar bgcolor[MAX_CHANNELS] = { 0 }; guchar *buf = NULL; gint x1, y1, x2, y2; gint width, height; diff --git a/app/core/gimppickable-contiguous-region.cc b/app/core/gimppickable-contiguous-region.cc index a099c7fcf6..433c3f5324 100644 --- a/app/core/gimppickable-contiguous-region.cc +++ b/app/core/gimppickable-contiguous-region.cc @@ -148,6 +148,9 @@ gimp_pickable_contiguous_region_by_seed (GimpPickable *pickable, format = choose_format (src_buffer, select_criterion, &n_components, &has_alpha); + + g_return_val_if_fail (n_components <= MAX_CHANNELS, NULL); + gegl_buffer_sample (src_buffer, x, y, NULL, start_col, format, GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE); @@ -228,6 +231,8 @@ gimp_pickable_contiguous_region_by_color (GimpPickable *pickable, format = choose_format (src_buffer, select_criterion, &n_components, &has_alpha); + g_return_val_if_fail (n_components <= MAX_CHANNELS, NULL); + gegl_color_get_pixel (color, format, start_col); if (has_alpha)