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).
This commit is contained in:
Jehan 2026-04-01 15:58:00 +02:00
parent 08121e09bd
commit 9257af7570
4 changed files with 12 additions and 4 deletions

View file

@ -30,7 +30,7 @@
/* former base/ defines */
#define MAX_CHANNELS 4
#define MAX_CHANNELS 5
#define RED 0
#define GREEN 1

View file

@ -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));

View file

@ -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;

View file

@ -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)